<.comboboxid="dog-breed-selector"name="breed"list_label="Dogbreeds"options={[[key:"Labrador Retriever",value:"labrador",description:"Friendly and outgoing"],[key:"German Shepherd",value:"german_shepherd",description:"Confident and smart"],[key:"Bulldog",value:"bulldog",description:"Docile and willful",disabled:true]]}/>
Label
The component does not render a label by itself, so you must render one
yourself. This is important for accessibility: without it the text input has
no accessible name, and a screen reader announces it as a combobox without
saying what is being chosen.
The usual way is a <label> whose for attribute is the id you passed:
The component renders a hidden input with the given name. Its value is the
selected option value, or, if a free text entry is selected, the entered
value.
The text input the user types uses the given name with a _search suffix.
The submitted value is either the label of the selected option or
the current search term. You can use this value to filter options on the
server side, or otherwise ignore it.
With a clear button
If the clearable attribute is set, a clear button is rendered that
unselects the current selection and clears the search term.
Set on_search to filter on the server. If set, the hook stops filtering on
the client side, and your handler receives the typed text as the *_search
parameter described above.
Instead of an event name, you can also pass a Phoenix.LiveView.JS command.
Keyboard
Down - open the listbox, or move to the next option. Opening moves to
the selected option, or to the first one if nothing is selected.
Up - open the listbox at the last option, or move to the previous one.
Alt + Down - open the listbox without moving to an option.
Alt + Up - close the listbox, leaving the text as it is.
Enter - select the active option.
Escape - close the listbox and put the display value of the selection
back in the input. With the listbox already closed and the display value
unchanged, clear the selection.
The combobox is a single tab stop. Focus stays on the text input and never
moves into the listbox. The active option is tracked with
aria-activedescendant. The toggle and the clear button are out of the tab
order; keyboard users can use Alt + Down and Alt + Up for the
toggle, and Escape for clearing.
Home, End, Left, Right, Backspace and Delete are not intercepted
and are reserved for the browser's text editing.
<.comboboxid="combobox-single-with-labels-and-descriptions"name="breed"value="labrador"options={[[key:"Labrador Retriever",value:"labrador",description:"Friendly and outgoing"],[key:"German Shepherd",value:"german_shepherd",description:"Confident and smart"],[key:"French Bulldog",value:"french_bulldog",description:"Adaptable and playful",disabled:true]]}aria-label="Dogbreed"list_label="Dogbreeds"/>
<.comboboxid="combobox-single-with-groups-and-descriptions"name="breed"value="golden_retriever"options={[{"Retrievers",[[key:"Labrador Retriever",value:"labrador",description:"Friendly and outgoing"],[key:"Golden Retriever",value:"golden_retriever",description:"Intelligent and friendly"]]},:hr,{"Bulldogs",[[key:"French Bulldog",value:"french_bulldog",description:"Adaptable and playful"],[key:"Bulldog",value:"bulldog",description:"Docile and willful",disabled:true]]},[key:"German Shepherd",value:"german_shepherd",description:"Confident and smart"]]}aria-label="Dogbreed"list_label="Dogbreeds"/>