Skip to content

Commit d57f232

Browse files
committed
also added focus
1 parent 36ae140 commit d57f232

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

thaw/src/button/button/types.rs

+7
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,11 @@ impl ButtonRef {
120120
_ = button_el.click();
121121
}
122122
}
123+
124+
/// Focus the button element.
125+
pub fn focus(&self) {
126+
if let Some(button_el) = self.button_ref.get_untracked() {
127+
_ = button_el.focus();
128+
}
129+
}
123130
}

thaw/src/button/docs/mod.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,14 @@ let click = move |_| {
209209
button_ref.get_untracked().unwrap().click()
210210
};
211211

212+
let focus = move |_| {
213+
button_ref.get_untracked().unwrap().focus()
214+
};
215+
212216
view! {
213217
<Space>
214218
<Button on_click=click>"Click"</Button>
219+
<Button on_click=focus>"Focus"</Button>
215220
<Button comp_ref=button_ref on_click>{count}</Button>
216221
</Space>
217222
}
@@ -244,6 +249,7 @@ view! {
244249

245250
### ButtonRef Props
246251

247-
| Name | Type | Description |
248-
| ----- | ----------- | ------------------------ |
252+
| Name | Type | Description |
253+
| ----- | ----------- | ------------------------- |
249254
| click | `Fn(&self)` | Click the button element. |
255+
| focus | `Fn(&self)` | Focus the button element. |

0 commit comments

Comments
 (0)