ZUI

Search documentation

Find a page or a heading.

Combobox

A field that picks one or any number of a long list of choices, searched by typing.

Installation

bash

The CLI writes components/ui/combobox.tsx, installs Button, Command, Popover, Icon, Text, Text children and Utils, and adds lucide-react-native. The list draws in the app's PortalHost; see Add a portal host.

Usage

tsx
tsx

Multiple

tsx

Clear

tsx

API reference

Combobox

Without value the Combobox holds the chosen value, starting from defaultValue; null is nothing chosen. With multiple it holds a list of values, and a press on an item chooses it or lets go of it, leaving the list open. items gives each value its label, so the trigger shows it before the list has first been opened, and gives a function child of ComboboxList its items; a string is its own label and value.

ComboboxTrigger

Takes every prop of Button. It is an outline Button with a chevron at its end, announced as a combobox, expanded while the list is open; name it with aria-label.

ComboboxValue

Takes every prop of Text, plus placeholder, shown muted while nothing is chosen. With multiple it shows the chosen labels, each after a comma. A function child gets the chosen values as a list and draws what it returns in place of the Text, such as a ComboboxChip for each.

ComboboxChips

Takes every prop of React Native's View, plus aria-invalid. The field of a multiple Combobox in place of a ComboboxTrigger: a wrapping row of chips with a ComboboxChipsInput at its end. A press on it opens the list below it. It takes the focus border while the list is open, and the destructive border while aria-invalid.

ComboboxChip

Takes every prop of View, plus value and showRemove (true). Text children are its label. Its remove button, a ghost icon button named Remove and the label, lets go of value; without value, the chosen value whose value or label is its text.

ComboboxChipsInput

Takes every prop of React Native's Pressable, plus placeholder, shown muted. It opens and closes the list, and is announced as a combobox, expanded while the list is open; name it with aria-label.

ComboboxClear

Takes every prop of Button. A ghost icon button named Clear, drawn while something is chosen, that lets go of every chosen item. A multiple Combobox reports the empty list through onValueChange. A single Combobox does not call onValueChange, so the owner of its value sets it to null in the button's onPress.

ComboboxContent

Takes every prop of PopoverContent, with align ('start') and sideOffset (6). It holds a Command, so its parts filter and are run as a Command's are. It opens with the chosen item highlighted.

ComboboxInput

Takes every prop of CommandInput. It is focused as the list opens, which raises the keyboard on a device.

ComboboxList

Takes every prop of CommandList. Its children may be a function of each of the Combobox's items, given as { label, value }.

ComboboxItem

Takes every prop of CommandItem but onSelect, checked and keywords, plus value and label. Text children are its label; give label when the children draw something else. It is announced as selected while chosen, with a check mark at its end. A press, or the return key while it is highlighted, chooses it and closes the list.

ComboboxGroup, ComboboxLabel, ComboboxEmpty and ComboboxSeparator

The group holds items that belong together and is hidden while none of them match; the label is the muted heading over it. The empty message shows while the typed text matches no item, and the separator is a hairline between groups.

Differences from upstream

  • Upstream builds on Base UI's Combobox, which draws only on the web. The native one is a Popover holding a Command, as upstream's popup example lays it out: the input sits in the list's panel, not in the field.
  • The input draws a search icon at its start, as a Command's does. showTrigger and showClear are left out.
  • A function child of ComboboxList gets each item as { label, value }, a string item included.
  • ComboboxChipsInput is a button that opens the list, not a text field: the search is typed into the ComboboxInput in the list's panel, as in a single Combobox, since a field outside the panel would sit under the layer that closes it on a press. ComboboxChips anchors the list itself, so useComboboxAnchor is left out.
  • A single Combobox's onValueChange is never called with null, which would change its type for every app holding the value as a string; a ComboboxClear's onPress reports the clear instead.
  • A function child of ComboboxValue gets the chosen values as a list in a single Combobox too, one at most.
  • ComboboxClear stands on its own, beside the trigger or in the chips, where upstream's sits in its ComboboxInput's showClear.