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

Improve Combobox Input value #1248

Merged
merged 2 commits into from
Mar 16, 2022
Merged

Improve Combobox Input value #1248

merged 2 commits into from
Mar 16, 2022

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Mar 16, 2022

This PR improves upon this PR: #1181

In that PR we ignored syncing when your value was set to undefined, that means that if you "reset" your value to undefined that the old value was still present in the Input. To fix this, we will always sync (unless we don't have an input field).
This means that your displayValue should always return something. It could happen that you have to write this:

(React example)

<Combobox.Input displayValue={person => person?.name} />

This would have resulted in "undefined" in the input, so we will also make sure that null and undefined values are converted to an empty string (''). It's important that we use ?? '' and not || '', otherwise values like 0 would be converted to an empty string as well.

@vercel
Copy link

vercel bot commented Mar 16, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

headlessui-react – ./packages/playground-react

🔍 Inspect: https://vercel.com/tailwindlabs/headlessui-react/77mPiqGfvXccDrtG3XKtbUsM95xr
✅ Preview: https://headlessui-react-git-reset-input-on-value-change-tailwindlabs.vercel.app

headlessui-vue – ./packages/playground-vue

🔍 Inspect: https://vercel.com/tailwindlabs/headlessui-vue/6EzycDAiyWqND4i54EXsjogTkcu4
✅ Preview: https://headlessui-vue-git-reset-input-on-value-change-tailwindlabs.vercel.app

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.

1 participant