Skip to content

Commit

Permalink
Add bindings for FocusOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielleHuisman committed Jun 24, 2024
1 parent 9beb4c3 commit ea38d2f
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
* Add experimental bindings for User Agent Client Hints API
[#3989](https://github.com/rustwasm/wasm-bindgen/pull/3989)

* Add bindings for `FocusOptions`.
[#3996](https://github.com/rustwasm/wasm-bindgen/pull/3996)

### Changed

* Stabilize Web Share API.
Expand Down
1 change: 1 addition & 0 deletions crates/web-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ FlashClassification = []
FlowControlType = []
FocusEvent = ["Event", "UiEvent"]
FocusEventInit = []
FocusOptions = []
FontData = []
FontFace = []
FontFaceDescriptors = []
Expand Down
46 changes: 46 additions & 0 deletions crates/web-sys/src/features/gen_FocusOptions.rs
Original file line number Diff line number Diff line change
@@ -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()
}
}
8 changes: 8 additions & 0 deletions crates/web-sys/src/features/gen_HtmlElement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
}
7 changes: 7 additions & 0 deletions crates/web-sys/src/features/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions crates/web-sys/webidls/enabled/FocusOptions.webidl
Original file line number Diff line number Diff line change
@@ -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;
};
2 changes: 1 addition & 1 deletion crates/web-sys/webidls/enabled/HTMLElement.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit ea38d2f

Please sign in to comment.