Set default value when input is empty to ComboBox? #2789
-
I have a Timezone ComboBox that is field with a specific value like Now when I empty the input field, it becomes empty. But when I focus out of it, it doesn't go back to the original timezone like I want it to go to the original timezone value instead of being empty when I click outside it. How do I do it? And nope, don't say <ComboBox
label="Timezone"
defaultInputValue={tz}
defaultItems={options}
onSelectionChange={changeTimezone}
>
{(item) => <Item key={item.label}>{item.label}</Item>}
</ComboBox> Bdw, the ComboBox is perfect. I managed to make it work with Tailwind with my own styling although I do prefer Headless UI APIs but it works 🤷♂️ |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
|
Beta Was this translation helpful? Give feedback.
-
@deadcoder0904 You can view uncontrolled props ( |
Beta Was this translation helpful? Give feedback.
-
I got it working for my real app but this fake demo doesn't show it the 1st time,i.e, on reload even though I have selected Anyways, here's the Codesandbox → https://codesandbox.io/s/combobox-with-fzf-496ub?file=/src/App.tsx The main logic is in the const onBlur = (e: any) => {
const tz = e.target.value;
if (!timezonesList.map((item) => item.key).includes(tz)) {
setInputValue(defaultTz); // here it should be actual database value
}
}; Thanks, @LFDanLu & @reidbarber for the help 🙌 |
Beta Was this translation helpful? Give feedback.
I got it working for my real app but this fake demo doesn't show it the 1st time,i.e, on reload even though I have selected
defaultSelectedKey
just like in my real app.Anyways, here's the Codesandbox → https://codesandbox.io/s/combobox-with-fzf-496ub?file=/src/App.tsx
The main logic is in the
onBlur
plus a bunch of other things to make it work:Thanks, @LFDanLu & @reidbarber for the help 🙌