Commit c9f8f30
authored
Fix
This PR fixes an issue where if a Listbox does not have a value yet, and
it's opened via an ArrowUp or ArrowDown (on the ListboxButton) then it
didn't correctly go to the firs or last option.
Before, we were opening the listbox in a `flushSync()` call, after that
call we were focusing the first or last option depending on if you used
the ArrowDown or ArrowUp keys.
However, the options can and will be registered at a later point in
time, which means that the focus of first or last option is technically
going to fail because no options are available yet.
With this fix we don't need the `flushSync` call, and instead we
passthrough a pending focus. Once the options are registered, if a
pending focus is present, only then will we focus the correct option.
This gets rid of timing issues.Listbox not focusing first or last option on ArrowUp/ArrowDown (#3721)1 parent 0b8deaf commit c9f8f30
File tree
3 files changed
+33
-10
lines changed- packages/@headlessui-react
- src/components/listbox
3 files changed
+33
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
Lines changed: 29 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
| 64 | + | |
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
| |||
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
114 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
115 | 119 | | |
116 | 120 | | |
117 | 121 | | |
| |||
138 | 142 | | |
139 | 143 | | |
140 | 144 | | |
| 145 | + | |
141 | 146 | | |
142 | 147 | | |
143 | 148 | | |
144 | 149 | | |
145 | | - | |
| 150 | + | |
146 | 151 | | |
147 | 152 | | |
148 | 153 | | |
| |||
155 | 160 | | |
156 | 161 | | |
157 | 162 | | |
158 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
159 | 170 | | |
160 | 171 | | |
161 | 172 | | |
| |||
311 | 322 | | |
312 | 323 | | |
313 | 324 | | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
314 | 333 | | |
315 | 334 | | |
316 | 335 | | |
| |||
325 | 344 | | |
326 | 345 | | |
327 | 346 | | |
| 347 | + | |
328 | 348 | | |
329 | 349 | | |
330 | 350 | | |
| |||
385 | 405 | | |
386 | 406 | | |
387 | 407 | | |
| 408 | + | |
| 409 | + | |
388 | 410 | | |
389 | 411 | | |
390 | 412 | | |
| |||
464 | 486 | | |
465 | 487 | | |
466 | 488 | | |
467 | | - | |
468 | | - | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
469 | 493 | | |
470 | 494 | | |
471 | 495 | | |
| |||
Lines changed: 3 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
404 | 404 | | |
405 | 405 | | |
406 | 406 | | |
407 | | - | |
408 | | - | |
| 407 | + | |
409 | 408 | | |
410 | 409 | | |
411 | 410 | | |
412 | 411 | | |
413 | | - | |
414 | | - | |
| 412 | + | |
415 | 413 | | |
416 | 414 | | |
417 | 415 | | |
| |||
435 | 433 | | |
436 | 434 | | |
437 | 435 | | |
438 | | - | |
| 436 | + | |
439 | 437 | | |
440 | 438 | | |
441 | 439 | | |
| |||
0 commit comments