Repository navigation
Whats the recommended way of handling onClick event on Combobox for new value? #3728
Unanswered
bouteillerAlan
asked this question in
Help
Replies: 1 comment
|
Handle the "create" option where every selection lands, in the Combobox const [selectedEditor, setSelectedEditor] = useState<Editor | null>(null)
function createNewEditor(name: string): void {
createEditor({ name: formatText(name) })
.unwrap()
.then((data) => onChange(data.resource.id))
.catch(() => onChange(''))
}
<Combobox
value={selectedEditor}
onChange={(editor: Editor | null) => {
setSelectedEditor(editor)
if (editor && editor.id === null) createNewEditor(editor.name)
}}
onClose={() => setQuery('')}
>
{/* input unchanged */}
<ComboboxOptions anchor="bottom" className="border empty:invisible">
{query && (
<ComboboxOption value={{ id: null, name: query }} className="data-focus:bg-blue-100">
{`Creer ${query}`}
</ComboboxOption>
)}
{/* existing options unchanged */}
</ComboboxOptions>
</Combobox>The state also changes from a string to |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hey, I want to allow my user to execute the function
createNewOption()when it clicks on the new value set on my combobox (exactly like in the documentation), but the onClick event does absolutely nothing. What is the way to handle that?All reactions