Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Make SwitchField component clickable from the keyboard when focused (#35830)
Anthony Eid7965052757f2
diff --git a/crates/ui/src/components/toggle.rs b/crates/ui/src/components/toggle.rsindex 59c056859de..e5f28e3b255 100644--- a/crates/ui/src/components/toggle.rs+++ b/crates/ui/src/components/toggle.rs@@ -420,7 +420,7 @@ pub struct Switch {id: ElementId,toggle_state: ToggleState,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>,key_binding: Option<KeyBinding>,color: SwitchColor,@@ -459,7 +459,7 @@ impl Switch {mut self,handler: impl Fn(&ToggleState, &mut Window, &mut App) + 'static,) -> Self {- self.on_click = Some(Box::new(handler));+ self.on_click = Some(Rc::new(handler));self}@@ -513,10 +513,16 @@ impl RenderOnce for Switch {.when_some(self.tab_index.filter(|_| !self.disabled),|this, tab_index| {- this.tab_index(tab_index).focus(|mut style| {- style.border_color = Some(cx.theme().colors().border_focused);- style- })+ this.tab_index(tab_index)+ .focus(|mut 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(