Fix dropdown click to lose focus. (#80)

This commit is contained in:
Jason Lee 2024-07-29 19:00:17 +08:00 committed by GitHub
parent 6e58edd349
commit 8aaeb9383d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 10 additions and 7 deletions

View file

@ -306,7 +306,7 @@ impl FocusableView for MyPanel {
}
}
impl Render for MyPanel {
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl IntoElement {
fn render(&mut self, _: &mut ViewContext<Self>) -> impl IntoElement {
div().id("my-panel").size_full().child(self.view.clone())
}
}

View file

@ -432,7 +432,6 @@ where
div()
.id(self.id.clone())
.key_context("Dropdown")
.group(format!("dropdown-group:{}", self.id))
.track_focus(&self.focus_handle)
.on_action(cx.listener(Self::up))
.on_action(cx.listener(Self::down))
@ -440,11 +439,10 @@ where
.on_action(cx.listener(Self::escape))
.size_full()
.relative()
.input_text_size(self.size)
.child(
div()
.id(ElementId::Name(
format!("dropdown-input:{}", self.id).into(),
))
.id("dropdown-input")
.relative()
.flex()
.w_full()
@ -468,7 +466,7 @@ where
.child(div().flex_1().child(self.display_title(cx)))
.when(show_clean, |this| {
this.child(
Button::new("clean-text", cx)
Button::new("clean", cx)
.icon(IconName::Close)
.style(ButtonStyle::Ghost)
.size(px(14.))
@ -485,7 +483,7 @@ where
),
)
.child(DropdownMenuElement {
id: ElementId::Name(format!("dropdown-menu:{}", self.id).into()),
id: "dropdown-menu".into(),
dropdown: cx.view().clone(),
})
}

View file

@ -351,6 +351,7 @@ where
.on_mouse_down(
MouseButton::Left,
cx.listener(move |this, _, cx| {
cx.stop_propagation();
this.selected_index = Some(ix);
this.action_confirm(&Confirm, cx);
}),

View file

@ -632,6 +632,8 @@ where
.on_mouse_down(
gpui::MouseButton::Left,
cx.listener(|_, _, cx| {
cx.stop_propagation();
PopoverWindowState::close_window(cx);
}),
),

View file

@ -140,6 +140,7 @@ impl RenderOnce for Switch {
self.on_click.filter(|_| !self.disabled),
|this, on_click| {
this.on_mouse_down(gpui::MouseButton::Left, move |_, cx| {
cx.stop_propagation();
on_click(&!self.checked, cx);
})
},

View file

@ -550,6 +550,7 @@ where
.on_mouse_down(
MouseButton::Left,
cx.listener(move |this, _, cx| {
cx.stop_propagation();
this.on_col_head_click(col_ix, cx);
}),
)