Skip to content

Commit 71bd366

Browse files
Add bindings for FocusOptions (#3996)
1 parent 9beb4c3 commit 71bd366

File tree

7 files changed

+79
-1
lines changed

7 files changed

+79
-1
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
* Add experimental bindings for User Agent Client Hints API
3737
[#3989](https://github.com/rustwasm/wasm-bindgen/pull/3989)
3838

39+
* Add bindings for `FocusOptions`.
40+
[#3996](https://github.com/rustwasm/wasm-bindgen/pull/3996)
41+
3942
### Changed
4043

4144
* Stabilize Web Share API.

crates/web-sys/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ FlashClassification = []
418418
FlowControlType = []
419419
FocusEvent = ["Event", "UiEvent"]
420420
FocusEventInit = []
421+
FocusOptions = []
421422
FontData = []
422423
FontFace = []
423424
FontFaceDescriptors = []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#![allow(unused_imports)]
2+
#![allow(clippy::all)]
3+
use super::*;
4+
use wasm_bindgen::prelude::*;
5+
#[wasm_bindgen]
6+
extern "C" {
7+
# [wasm_bindgen (extends = :: js_sys :: Object , js_name = FocusOptions)]
8+
#[derive(Debug, Clone, PartialEq, Eq)]
9+
#[doc = "The `FocusOptions` dictionary."]
10+
#[doc = ""]
11+
#[doc = "*This API requires the following crate features to be activated: `FocusOptions`*"]
12+
pub type FocusOptions;
13+
#[wasm_bindgen(method, setter = "focusVisible")]
14+
fn focus_visible_shim(this: &FocusOptions, val: bool);
15+
#[wasm_bindgen(method, setter = "preventScroll")]
16+
fn prevent_scroll_shim(this: &FocusOptions, val: bool);
17+
}
18+
impl FocusOptions {
19+
#[doc = "Construct a new `FocusOptions`."]
20+
#[doc = ""]
21+
#[doc = "*This API requires the following crate features to be activated: `FocusOptions`*"]
22+
pub fn new() -> Self {
23+
#[allow(unused_mut)]
24+
let mut ret: Self = ::wasm_bindgen::JsCast::unchecked_into(::js_sys::Object::new());
25+
ret
26+
}
27+
#[doc = "Change the `focusVisible` field of this object."]
28+
#[doc = ""]
29+
#[doc = "*This API requires the following crate features to be activated: `FocusOptions`*"]
30+
pub fn focus_visible(&mut self, val: bool) -> &mut Self {
31+
self.focus_visible_shim(val);
32+
self
33+
}
34+
#[doc = "Change the `preventScroll` field of this object."]
35+
#[doc = ""]
36+
#[doc = "*This API requires the following crate features to be activated: `FocusOptions`*"]
37+
pub fn prevent_scroll(&mut self, val: bool) -> &mut Self {
38+
self.prevent_scroll_shim(val);
39+
self
40+
}
41+
}
42+
impl Default for FocusOptions {
43+
fn default() -> Self {
44+
Self::new()
45+
}
46+
}

crates/web-sys/src/features/gen_HtmlElement.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1540,4 +1540,12 @@ extern "C" {
15401540
#[doc = ""]
15411541
#[doc = "*This API requires the following crate features to be activated: `HtmlElement`*"]
15421542
pub fn focus(this: &HtmlElement) -> Result<(), JsValue>;
1543+
#[cfg(feature = "FocusOptions")]
1544+
# [wasm_bindgen (catch , method , structural , js_class = "HTMLElement" , js_name = focus)]
1545+
#[doc = "The `focus()` method."]
1546+
#[doc = ""]
1547+
#[doc = "[MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus)"]
1548+
#[doc = ""]
1549+
#[doc = "*This API requires the following crate features to be activated: `FocusOptions`, `HtmlElement`*"]
1550+
pub fn focus_with_options(this: &HtmlElement, options: &FocusOptions) -> Result<(), JsValue>;
15431551
}

crates/web-sys/src/features/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -2707,6 +2707,13 @@ mod gen_FocusEventInit;
27072707
#[allow(unused_imports)]
27082708
pub use gen_FocusEventInit::*;
27092709

2710+
#[cfg(feature = "FocusOptions")]
2711+
#[allow(non_snake_case)]
2712+
mod gen_FocusOptions;
2713+
#[cfg(feature = "FocusOptions")]
2714+
#[allow(unused_imports)]
2715+
pub use gen_FocusOptions::*;
2716+
27102717
#[cfg(feature = "FontData")]
27112718
#[allow(non_snake_case)]
27122719
mod gen_FontData;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2+
/* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
4+
* You can obtain one at http://mozilla.org/MPL/2.0/.
5+
*
6+
* The origin of this IDL file is:
7+
* https://html.spec.whatwg.org/multipage/interaction.html#focusoptions
8+
*/
9+
10+
dictionary FocusOptions {
11+
boolean preventScroll = false;
12+
boolean focusVisible;
13+
};

crates/web-sys/webidls/enabled/HTMLElement.webidl

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ interface HTMLElement : Element {
4242
[CEReactions, SetterThrows, Pure]
4343
attribute long tabIndex;
4444
[Throws]
45-
undefined focus();
45+
undefined focus(optional FocusOptions options = {});
4646
[Throws]
4747
undefined blur();
4848
[CEReactions, SetterThrows, Pure]

0 commit comments

Comments
 (0)