diff --git a/CHANGELOG.md b/CHANGELOG.md index 14ed67d1e22f..8c8f3aeb6a48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,9 @@ * Add bindings for `queueMicrotask`. [#3981](https://github.com/rustwasm/wasm-bindgen/pull/3981) +* Add bindings for `FocusOptions`. + [#3996](https://github.com/rustwasm/wasm-bindgen/pull/3996) + ### Changed * Stabilize Web Share API. diff --git a/crates/web-sys/Cargo.toml b/crates/web-sys/Cargo.toml index 3ddd4511d29f..761973e9457e 100644 --- a/crates/web-sys/Cargo.toml +++ b/crates/web-sys/Cargo.toml @@ -418,6 +418,7 @@ FlashClassification = [] FlowControlType = [] FocusEvent = ["Event", "UiEvent"] FocusEventInit = [] +FocusOptions = [] FontData = [] FontFace = [] FontFaceDescriptors = [] diff --git a/crates/web-sys/src/features/gen_FocusOptions.rs b/crates/web-sys/src/features/gen_FocusOptions.rs new file mode 100644 index 000000000000..0efdeef5c816 --- /dev/null +++ b/crates/web-sys/src/features/gen_FocusOptions.rs @@ -0,0 +1,46 @@ +#![allow(unused_imports)] +#![allow(clippy::all)] +use super::*; +use wasm_bindgen::prelude::*; +#[wasm_bindgen] +extern "C" { + # [wasm_bindgen (extends = :: js_sys :: Object , js_name = FocusOptions)] + #[derive(Debug, Clone, PartialEq, Eq)] + #[doc = "The `FocusOptions` dictionary."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `FocusOptions`*"] + pub type FocusOptions; + #[wasm_bindgen(method, setter = "focusVisible")] + fn focus_visible_shim(this: &FocusOptions, val: bool); + #[wasm_bindgen(method, setter = "preventScroll")] + fn prevent_scroll_shim(this: &FocusOptions, val: bool); +} +impl FocusOptions { + #[doc = "Construct a new `FocusOptions`."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `FocusOptions`*"] + pub fn new() -> Self { + #[allow(unused_mut)] + let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new()); + ret + } + #[doc = "Change the `focusVisible` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `FocusOptions`*"] + pub fn focus_visible(&mut self, val: bool) -> &mut Self { + self.focus_visible_shim(val); + self + } + #[doc = "Change the `preventScroll` field of this object."] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `FocusOptions`*"] + pub fn prevent_scroll(&mut self, val: bool) -> &mut Self { + self.prevent_scroll_shim(val); + self + } +} +impl Default for FocusOptions { + fn default() -> Self { + Self::new() + } +} diff --git a/crates/web-sys/src/features/gen_HtmlElement.rs b/crates/web-sys/src/features/gen_HtmlElement.rs index e32594002310..24149ad95874 100644 --- a/crates/web-sys/src/features/gen_HtmlElement.rs +++ b/crates/web-sys/src/features/gen_HtmlElement.rs @@ -1540,4 +1540,12 @@ extern "C" { #[doc = ""] #[doc = "*This API requires the following crate features to be activated: `HtmlElement`*"] pub fn focus(this: &HtmlElement) -> Result<(), JsValue>; + #[cfg(feature = "FocusOptions")] + # [wasm_bindgen (catch , method , structural , js_class = "HTMLElement" , js_name = focus)] + #[doc = "The `focus()` method."] + #[doc = ""] + #[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus)"] + #[doc = ""] + #[doc = "*This API requires the following crate features to be activated: `FocusOptions`, `HtmlElement`*"] + pub fn focus_with_options(this: &HtmlElement, options: &FocusOptions) -> Result<(), JsValue>; } diff --git a/crates/web-sys/src/features/mod.rs b/crates/web-sys/src/features/mod.rs index 098735ffc140..c34777b79214 100644 --- a/crates/web-sys/src/features/mod.rs +++ b/crates/web-sys/src/features/mod.rs @@ -2707,6 +2707,13 @@ mod gen_FocusEventInit; #[allow(unused_imports)] pub use gen_FocusEventInit::*; +#[cfg(feature = "FocusOptions")] +#[allow(non_snake_case)] +mod gen_FocusOptions; +#[cfg(feature = "FocusOptions")] +#[allow(unused_imports)] +pub use gen_FocusOptions::*; + #[cfg(feature = "FontData")] #[allow(non_snake_case)] mod gen_FontData; diff --git a/crates/web-sys/webidls/enabled/FocusOptions.webidl b/crates/web-sys/webidls/enabled/FocusOptions.webidl new file mode 100644 index 000000000000..2a6725dfd773 --- /dev/null +++ b/crates/web-sys/webidls/enabled/FocusOptions.webidl @@ -0,0 +1,13 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. + * + * The origin of this IDL file is: + * https://html.spec.whatwg.org/multipage/interaction.html#focusoptions + */ + +dictionary FocusOptions { + boolean preventScroll = false; + boolean focusVisible; +}; diff --git a/crates/web-sys/webidls/enabled/HTMLElement.webidl b/crates/web-sys/webidls/enabled/HTMLElement.webidl index 196638e71fbc..f6516c3ad88f 100644 --- a/crates/web-sys/webidls/enabled/HTMLElement.webidl +++ b/crates/web-sys/webidls/enabled/HTMLElement.webidl @@ -42,7 +42,7 @@ interface HTMLElement : Element { [CEReactions, SetterThrows, Pure] attribute long tabIndex; [Throws] - undefined focus(); + undefined focus(optional FocusOptions options = {}); [Throws] undefined blur(); [CEReactions, SetterThrows, Pure]