feat(list_item): Add stop_propagation/prevent_default when trigger click event (#273)

This commit is contained in:
Floyd Wang 2024-09-26 11:55:02 +08:00 committed by GitHub
parent 098315ee92
commit d2f26795eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 3 deletions

View file

@ -1,7 +1,7 @@
use anyhow::Result;
use gpui::*;
use prelude::FluentBuilder as _;
use private::serde::Deserialize;
use serde::Deserialize;
use std::{sync::Arc, time::Duration};
use story::{
ButtonStory, CalendarStory, DropdownStory, IconStory, ImageStory, InputStory, ListStory,

View file

@ -1,6 +1,6 @@
use gpui::{
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,
};
use smallvec::SmallVec;
@ -128,7 +128,12 @@ impl RenderOnce for ListItem {
.justify_between()
.when_some(self.on_click, |this, on_click| {
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 {
this
}