Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add frozen value to ComboboxOptions component #3126

Merged
merged 4 commits into from
Apr 24, 2024

Conversation

RobinMalfait
Copy link
Member

This PR introduces a frozen value, similar to the Listbox component. This allows us to keep the visual state of the "old" value when selecting a new value.

The reason for this is that when you select a value, the combobox will close and in a lot of cases a (fade out) transition is happening. If we change the selected state to the new value, then the UI will flicker (or at least changes visual state) when the transition is happening. This PR prevents that. This is also how the native <select> works.

Note: the Combobox and ComboboxInput still know about the correct newly selected value and will update aria-activedescendant information correctly.

Also note that this only happens in "single value mode", if you use the multiple prop, then the selected value will be updated immediately.

Copy link

vercel bot commented Apr 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
headlessui-react ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 24, 2024 5:18pm
headlessui-vue ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 24, 2024 5:18pm

Once you choose an option, the `selected` state remains on the "old"
value until the combobox is fully closed. This way the potential visual
indicators such as a check mark doesn't move around while the Combobox
is closing (when using transitions)

Same as the `Listbox`, this is purely about visual state and exposed
data from the `ComboboxOptions` component and down that tree. The
top-level `Combobox` and `ComboboxInput` components still know the
correct (new) value and will update the `aria-activedescendant`
correctly.

This is achieved by storing the old data (only in single value mode),
and overriding the `isSelected` check function via context provided by
the `ComboboxOptions` component.
But now with this change, it will be present.
@RobinMalfait RobinMalfait changed the title Add frozen value to ComboboxOption component Add frozen value to ComboboxOptions component Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants