Repository navigation
[select] Fire onClick during drag-to-select - #3969
Conversation
commit: |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Greptile OverviewGreptile SummaryThis PR updates Select drag-to-select so the item’s Main integration points:
Confidence Score: 2/5
Important Files Changed
|
| commitSelection(event.nativeEvent); | ||
| makeEventPreventable(event); | ||
| componentProps.onClick?.(event); | ||
|
|
||
| if (!event.baseUIHandlerPrevented) { | ||
| commitSelection(event.nativeEvent); | ||
| } |
There was a problem hiding this comment.
In MenuItem, we call itemRef.current.click() instead, I wonder if that's better for consistency
|
@atomiks Thanks for taking a look. Agree that doing Specifically, when a This also shows up outside |
Oh nice, thanks for the fix & explanation |
7c02ba6 to
b44c932
Compare
|
Couple lint issues:
|
Bundle size report
Check out the code infra dashboard for more information about this PR. |
| expect(screen.queryByRole('tooltip')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| test('inside click does not suppress the next outside click when no drag occurred', async () => { |
There was a problem hiding this comment.
Codex review found a logic regression here:
a normal inside click in intentional mode can leave endedOrStartedInsideRef set,
so the next outside click is incorrectly ignored once (even without a drag).
I can't reproduce it this on the Popover demo, though. The tests are only failing in JSDOM but not Chromium.
There was a problem hiding this comment.
@obeattie this seems like an edge case, but theoretically possible to trigger an issue
In-browser popover usage closes because real browser clicks fire the other mouse events (mousedown -> mouseup -> click). And in useDismiss, non-click events clear endedOrStartedInsideRef, so by the time outside click runs, it closes normally.
So it's an issue only if .click() runs without the mouse events (tests, assistive tech, programmatic clicks?)
There was a problem hiding this comment.
Thanks for the review and good catch. The only sane way I could think of to resolve this was to change the suppression logic to better tie the suppression to actual drag sequences.
Now, two flags are used for this:
pressStartedInsideRef: Tracks whether there's an active press that began inside. Always cleared inpointerup/mouseupsuppressNextOutsideClickRef: Tracks whether we want to ignore an outsideclickevent – set onpointerup/mouseup(which fire beforeclickand won't fire in the synthetic cases like the one we're now firing for drag-to-select).
Hopefully this works better!
73353df to
7d23e1a
Compare
Split endedOrStartedInsideRef into pressStartedInsideRef (tracks active press that began inside) and suppressNextOutsideClickRef (one-shot flag for when press starts inside and ends outside). Suppression now only activates after a real drag sequence, not any inside click, which fixes programmatic/AT clicks that don't fire intermediate mouse events.
3789c70 to
0fad799
Compare
|
Simplified the |
0fad799 to
8fb120c
Compare
9f34f5e to
55c6612
Compare
55c6612 to
9333be5
Compare
|
Anything more I can do to help here? |
|
@obeattie nope, sorry, I edited your PR and then found various issues caused by my edits, and spent awhile refining it the other day. I think its current state is good but I left it off the last release because it changes |
|
No worries - thank you for your effort! |
The drag-to-select behavior which was originally introduced in #541 (mousedown on trigger → drag to item → mouseup to select) bypasses the item's
onClickhandler since the browser doesn't fire aclickevent when mousedown and mouseup occur on different elements. This is inconsistent with the other ways to select an item: both regular clicks and keyboard selection both invokeonClickalready.This PR calls
onClickfromonMouseUpbefore committing the selection, allowingpreventBaseUIHandler()to cancel the selection.Includes tests. (Sorry about #3968 - I closed it by accident.)