Make SwitchField component clickable from the keyboard when focused (#35830)
Release Notes: - N/A
This commit is contained in:
parent
62270b33c2
commit
7965052757
1 changed files with 12 additions and 6 deletions
|
@ -420,7 +420,7 @@ pub struct Switch {
|
||||||
id: ElementId,
|
id: ElementId,
|
||||||
toggle_state: ToggleState,
|
toggle_state: ToggleState,
|
||||||
disabled: bool,
|
disabled: bool,
|
||||||
on_click: Option<Box<dyn Fn(&ToggleState, &mut Window, &mut App) + 'static>>,
|
on_click: Option<Rc<dyn Fn(&ToggleState, &mut Window, &mut App) + 'static>>,
|
||||||
label: Option<SharedString>,
|
label: Option<SharedString>,
|
||||||
key_binding: Option<KeyBinding>,
|
key_binding: Option<KeyBinding>,
|
||||||
color: SwitchColor,
|
color: SwitchColor,
|
||||||
|
@ -459,7 +459,7 @@ impl Switch {
|
||||||
mut self,
|
mut self,
|
||||||
handler: impl Fn(&ToggleState, &mut Window, &mut App) + 'static,
|
handler: impl Fn(&ToggleState, &mut Window, &mut App) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.on_click = Some(Box::new(handler));
|
self.on_click = Some(Rc::new(handler));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -513,10 +513,16 @@ impl RenderOnce for Switch {
|
||||||
.when_some(
|
.when_some(
|
||||||
self.tab_index.filter(|_| !self.disabled),
|
self.tab_index.filter(|_| !self.disabled),
|
||||||
|this, tab_index| {
|
|this, tab_index| {
|
||||||
this.tab_index(tab_index).focus(|mut style| {
|
this.tab_index(tab_index)
|
||||||
style.border_color = Some(cx.theme().colors().border_focused);
|
.focus(|mut style| {
|
||||||
style
|
style.border_color = Some(cx.theme().colors().border_focused);
|
||||||
})
|
style
|
||||||
|
})
|
||||||
|
.when_some(self.on_click.clone(), |this, on_click| {
|
||||||
|
this.on_click(move |_, window, cx| {
|
||||||
|
on_click(&self.toggle_state.inverse(), window, cx)
|
||||||
|
})
|
||||||
|
})
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue