You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR fixes an issue with the `Listbox` component where we didn't
freeze the value soon enough.
This happens when state lives in the parent, and is updated via an
`onChange`.
What is currently happening:
1. User clicks on a listbox option, this should do 3 things:
1. Call the `onChange` with the new value
2. Close the listbox
3. "Freeze" the value, so the old value is still showing while the
listbox options are closing.
The problem is that calling the `onChange` updates the value in the
parent, and the component re-renders with the new value. At the time we
freeze the value, we already received the new value so we are freezing
the incorrect value. This causes a visual glitch. See reproduction:
tailwindlabs/tailwind-plus-issues#1761
This PR fixes that by changing the order a little bit so we freeze the
value as early as possible.
So now, when the user clicks on an option, we trigger a `SelectOption`
action. This will track whether we should freeze the value or not in
state immediately. After that, we call the `onChange`, and then close
the listbox.
Since we know we want to freeze the value _before_ calling `onChange`,
we can be sure we are freezing the correct (old) value.
## Test plan
Made a little video but with a duration of 1000 instead of 100 so you
can clearly see the old value and no visual jumps while the listbox is
closing.
https://github.com/user-attachments/assets/971b8ff4-2b03-4f6e-99af-f21f14d37930Fixes: tailwindlabs/tailwind-plus-issues#1761
---------
Co-authored-by: Jordan Pittman <[email protected]>
Copy file name to clipboardExpand all lines: packages/@headlessui-react/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
15
15
- Infer `Combobox` type based on `onChange` handler ([#3798](https://github.com/tailwindlabs/headlessui/pull/3798))
16
16
- Allow home/end key default behavior inside `ComboboxInput` when `Combobox` is closed ([#3798](https://github.com/tailwindlabs/headlessui/pull/3798))
17
17
- Ensure interacting with a `Dialog` on iOS works after interacting with a disallowed area ([#3801](https://github.com/tailwindlabs/headlessui/pull/3801))
18
+
- Freeze Listbox values as soon as possible when closing ([#3802](https://github.com/tailwindlabs/headlessui/pull/3802))
0 commit comments