feat(list_item): Add stop_propagation/prevent_default when trigger click event (#273)
This commit is contained in:
parent
098315ee92
commit
d2f26795eb
2 changed files with 8 additions and 3 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use gpui::*;
|
use gpui::*;
|
||||||
use prelude::FluentBuilder as _;
|
use prelude::FluentBuilder as _;
|
||||||
use private::serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::{sync::Arc, time::Duration};
|
use std::{sync::Arc, time::Duration};
|
||||||
use story::{
|
use story::{
|
||||||
ButtonStory, CalendarStory, DropdownStory, IconStory, ImageStory, InputStory, ListStory,
|
ButtonStory, CalendarStory, DropdownStory, IconStory, ImageStory, InputStory, ListStory,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, prelude::FluentBuilder as _, AnyElement, ClickEvent, Div, ElementId, InteractiveElement,
|
div, prelude::FluentBuilder as _, AnyElement, ClickEvent, Div, ElementId, InteractiveElement,
|
||||||
IntoElement, MouseMoveEvent, ParentElement, RenderOnce, SharedString, Stateful,
|
IntoElement, MouseButton, MouseMoveEvent, ParentElement, RenderOnce, SharedString, Stateful,
|
||||||
StatefulInteractiveElement as _, Styled, WindowContext,
|
StatefulInteractiveElement as _, Styled, WindowContext,
|
||||||
};
|
};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
|
@ -128,7 +128,12 @@ impl RenderOnce for ListItem {
|
||||||
.justify_between()
|
.justify_between()
|
||||||
.when_some(self.on_click, |this, on_click| {
|
.when_some(self.on_click, |this, on_click| {
|
||||||
if !self.disabled {
|
if !self.disabled {
|
||||||
this.cursor_pointer().on_click(on_click)
|
this.cursor_pointer()
|
||||||
|
.on_mouse_down(MouseButton::Left, move |_, cx| {
|
||||||
|
cx.stop_propagation();
|
||||||
|
cx.prevent_default();
|
||||||
|
})
|
||||||
|
.on_click(on_click)
|
||||||
} else {
|
} else {
|
||||||
this
|
this
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue