Commit 0a14649
authored
Improve quick release by requiring some cursor movement (#3762)
This PR improves the quick release feature we have for Menu, Listbox and
Combobox components. This now ensures that your mouse was moved at least
`5px` before triggering the quick release action.
This odd behavior is most prevalent in Listbox components where the
`anchor="selection"` feature is used such that the options are rendered
on top of the Listbox button. Because of this, if you hold your cursor a
bit too long when clicking the Listbox it would immediately select the
option and close again.
With this improvement in place, you have to at least move your cursor
`5px`. This is an arbitrary value I picked so we can tweak it if we
wanted to, but `1px` to `3px` felt too small and `10px` felt too large.
### Test plan
When initially opening the Listbox, I'm holding down my cursor a bit
(but not moving!) and then releasing the "click".
#### Before:
Notice how the initial click results in the Listbox closing again once I
release the cursor.
https://github.com/user-attachments/assets/df8dc749-ce20-46c9-8815-ac817b789b7e
#### After:
Notice how the initial click results in the Listbox staying open even
after releasing the cursor. This is because we didn't move enough so we
don't register it as a quick release.
https://github.com/user-attachments/assets/f8d76a7b-1edd-4d9a-a8d3-120aadf49c571 parent 2ff307c commit 0a14649
File tree
2 files changed
+21
-1
lines changed- packages/@headlessui-react
- src/hooks
2 files changed
+21
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
Lines changed: 18 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
31 | 35 | | |
32 | 36 | | |
33 | 37 | | |
| |||
54 | 58 | | |
55 | 59 | | |
56 | 60 | | |
| 61 | + | |
| 62 | + | |
57 | 63 | | |
58 | 64 | | |
59 | 65 | | |
60 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
61 | 70 | | |
62 | 71 | | |
63 | 72 | | |
| |||
68 | 77 | | |
69 | 78 | | |
70 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
71 | 89 | | |
72 | 90 | | |
73 | 91 | | |
| |||
0 commit comments