Adding the ability to create new options in a Combobox when none are found
In some cases, you may want to allow users to create new options in a Combobox when they can't find what they're looking for. This is useful for fields like tags, categories, or any user-defined values where the list of options should be dynamic.
The pattern below shows how to add a "+ Create" option to the Combobox dropdown that appears:
The key aspects of this pattern:
__add_new__) to your options array
onSelectionChange handler, check if the selected value matches the sentinel and handle it differentlyThis example shows the "+ Create" option at the bottom of the list whenever the user has typed something:
This example only shows the "+ Create" option when the search returns no matching results:
In a real application, you'll likely want to persist newly created options to a backend: