Fix click events by notifying when we assign pending_mouse_down (#3329)

We need to notify when we set the pending mouse down so we attach the
mouse up event listener before the mouse button is released.

Release Notes:

- N/A
This commit is contained in:
Nathan Sobo 2023-11-14 19:55:23 -07:00 committed by GitHub
commit e37d7f5b0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -597,7 +597,7 @@ impl<V: 'static> ParentComponent<V> for Div<V> {
} }
impl<V: 'static> Element<V> for Div<V> { impl<V: 'static> Element<V> for Div<V> {
type ElementState = NodeState; type ElementState = DivState;
fn element_id(&self) -> Option<ElementId> { fn element_id(&self) -> Option<ElementId> {
self.interactivity.element_id.clone() self.interactivity.element_id.clone()
@ -617,7 +617,7 @@ impl<V: 'static> Element<V> for Div<V> {
child.initialize(view_state, cx); child.initialize(view_state, cx);
} }
NodeState { DivState {
interactive_state, interactive_state,
child_layout_ids: SmallVec::new(), child_layout_ids: SmallVec::new(),
} }
@ -706,7 +706,7 @@ impl<V: 'static> Component<V> for Div<V> {
} }
} }
pub struct NodeState { pub struct DivState {
child_layout_ids: SmallVec<[LayoutId; 4]>, child_layout_ids: SmallVec<[LayoutId; 4]>,
interactive_state: InteractiveElementState, interactive_state: InteractiveElementState,
} }
@ -911,11 +911,13 @@ where
} }
} }
*pending_mouse_down.lock() = None; *pending_mouse_down.lock() = None;
cx.notify();
}); });
} else { } else {
cx.on_mouse_event(move |_state, event: &MouseDownEvent, phase, _cx| { cx.on_mouse_event(move |_view_state, event: &MouseDownEvent, phase, cx| {
if phase == DispatchPhase::Bubble && bounds.contains_point(&event.position) { if phase == DispatchPhase::Bubble && bounds.contains_point(&event.position) {
*pending_mouse_down.lock() = Some(event.clone()); *pending_mouse_down.lock() = Some(event.clone());
cx.notify();
} }
}); });
} }