Components · Inputs
Combobox
A searchable list of values built from parts, for filters with search and for picking a few of many values as chips.
import { Combobox } from "@botiverse/raft-ui";A combobox is a list of values that people narrow down by typing. raft-ui gives it as parts: a filter that opens a list with a search row, a field that people type into, or a field of chips for several values. For a ready-made field driven by an array of options, use ComboboxSelect.
When to use
The full choice between pickers is in Choosing a component.
Anatomy
Combobox: the root. Holds the value, the typed text and the open state. Required.- What opens the list, one of (an inline list is always open, and its
ComboboxControlis only the search field):ComboboxTrigger: the filter button, with an icon, a label,ComboboxTriggerCountandComboboxTriggerIndicator;ComboboxControl: a field at the control height (44px on a phone, 34px on a desktop) with an ink border, holdingComboboxInput,ComboboxClearandComboboxTriggerIndicator;ComboboxChips: a field at least the control height, holding oneComboboxChipper chosen value, each with aComboboxChipRemove, thenComboboxInput.
ComboboxContent: the popup. Required.ComboboxHeader: the popup's top row, withComboboxLabeland aComboboxClear.ComboboxSeparatoris the hairline under it.ComboboxInputGroup: the search row at the top of the list, holdingComboboxInput.ComboboxList: the scrolling list ofComboboxItems, each with aComboboxItemIndicator(the check mark).ComboboxGroupandComboboxGroupLabelgroup them;ComboboxRowandComboboxCollectionlay out grids and nested collections.ComboboxEmpty: the line shown when nothing matches.ComboboxValue,ComboboxPortal,ComboboxPopup: lower-level parts.
Variants
Inline list
An inline list is always open, in the page or dialog rather than in a popup: <Combobox inline open>, with a ComboboxControl to search it and a ComboboxList under it, no ComboboxContent. Use it where choosing a row starts something, such as asking the server who in that conversation can't see a file. The arrow keys move the highlight through the rows while focus stays in the search field, and only Enter or a click chooses one, so that work happens once, for the row chosen. A ChoiceList chooses the row the arrow keys reach, as a radio group does, and would start it for every row passed.
- Pass
openwithinline: the list is always shown. Inside a Dialog, leaveopenfixed rather than binding it to the dialog's open state: the dialog unmounts the list when it closes. - Name the list with
aria-labelledbyonComboboxList, pointing at the heading above it (Recent, Results). - Show what was chosen the way the rest of the screen does (the commit button's label, a summary beside the list):
ComboboxItemIndicatoranddata-selectedmark it in the list. - To filter with your own search (ranked, from the server), pass
filter={null}, the rows to show asitems, and controlinputValue. Choosing a row leaves the search text as it was.
States
- Applied filter: a
ComboboxTriggerwith a value fills withinfo-softand shows the count. - No match:
ComboboxEmptysays what found nothing: No one matches "zz". - Focus: a chips field rings as a whole (States); the search row in the popup takes the inset ink outline (Elevation).
Behavior
- Filter the list as people type.
- Show
ComboboxEmptywhen nothing matches. Never leave an empty popup open. - With
multiple, keep the list open when a value is chosen. Clicking outside or Esc closes it. - Make a chosen value a chip on
fill-muted, with a remove button at its end. Typing continues after the last chip. - A chip sits 6px inside the field's outer edge and 6px from the next one, so it is 22px on a desktop and 32px on a phone and the field keeps the control height until the chips wrap. It wears
radius-chip, like every chip; its remove button wearsradius-sticker2px inside the chip, and its focus ring is drawn inside it, where the chip would clip one outside. The clear button in a field is 6px from the field's end, withradius-chip(Shape). - Put a chip's text in an element of its own (a
<span>): a long value truncates there, at the width of the field, with its whole text as the chip'stitle, and the remove button stays visible (Forms). - A value too long for the input ends in an ellipsis while people aren't typing in it, with its whole text as the input's
title(Forms). While they type, it scrolls as in any input, with notitle. - An item is as tall as its content: one line is 36px, and each further line adds only its own height, with the same space above and below the text (Forms).
- A long item wraps onto as many lines as it needs. The list grows to fit it up to 24rem (or the field's width, when that is wider), never past the screen less 8px on each side.
- The list stays on the side it opens on and shrinks to the room there, scrolling, as long as that room holds five options (
--popup-list-min-height). Only with less does it flip to the other side, and it opens beside its field only when neither side holds five options (Elevation). - The list keeps clear of the frame insets: where a shell keeps part of the window for itself (
--raft-frame-inset-top,--raft-frame-inset-start,--raft-frame-inset-end), it stops 8px from that part, not from the window's edge. The start and end insets are the corners of the top band, so they count only when its trigger is in the band; under it, it keeps its own padding from the window's edge (Page structure). The web sets none. - In a phone sheet or a drawer the list always stays under the sheet's head: with little room it takes the larger side of the field and scrolls;
collisionBoundary="clipping-ancestors"opts it out (Dialog). - For results that come from a server, pass
filter={null}so the list shows them as they are, and keep the typed text controlled.
Accessibility
Combobox wraps Base UI Combobox: a text input with role="combobox" that controls a listbox, with arrow-key navigation and the highlighted item announced.
- In an inline list, focus stays in the search field: the highlighted row is its
aria-activedescendant, the chosen one hasaria-selected="true". Enter on a highlighted row chooses it and doesn't submit the form around it; with no row highlighted, Enter submits as usual. Esc reaches the dialog around the list and closes it. - Name the input: with a
FieldLabel(Field), or witharia-labelon a search row in a popup (Search channels). - In a chips field, each chip's remove button and the input are reachable with the keyboard. Name each remove button after its value (Remove Bugen).
- Give
ComboboxCleara label that says what it clears when it shows only an icon.
API
Combobox
ComboboxChip
Also takes the attributes of its element.
ComboboxChipRemove
Also takes the attributes of its element.
ComboboxChips
Also takes the attributes of its element.
ComboboxClear
Also takes the attributes of its element.
ComboboxCollection
ComboboxControl
Also takes the attributes of its element.
ComboboxContent
Also takes the attributes of its element.
ComboboxEmpty
Also takes the attributes of its element.
ComboboxGroup
Also takes the attributes of its element.
ComboboxGroupLabel
Also takes the attributes of its element.
ComboboxHeader
Takes the attributes of its element.
ComboboxInput
Also takes the attributes of its element.
ComboboxInputGroup
Also takes the attributes of its element.
ComboboxItem
Also takes the attributes of its element.
ComboboxItemIndicator
Also takes the attributes of its element.
ComboboxLabel
Also takes the attributes of its element.
ComboboxList
Also takes the attributes of its element.
ComboboxPopup
Takes the attributes of its element.
ComboboxPortal
Also takes the attributes of its element.
ComboboxRow
Also takes the attributes of its element.
ComboboxSeparator
Takes the attributes of its element.
ComboboxTrigger
Also takes the attributes of its element.
ComboboxTriggerCount, ComboboxTriggerIndicator
Takes the attributes of its element.
ComboboxValue
Related
Changes
- 0.106.2 · ChangedList popups shrink and scroll on their side before flipping; the side axis is the last resort ([Elevation › Popups](https://raft-design.botiverse.build/foundations/elevation/#popups), [DropdownMenu › Long menus](https://raft-design.botiverse.build/components/dropdown-menu/#long-menus), [Popover › A long popover](https://raft-design.botiverse.build/components/popover/#a-long-popover)):
DropdownMenuContent,SelectContent,ComboboxContent, ComboboxSelect on a desktop and aPopoverContentwith aPopoverBodystay on the side they open on and shrink to the room there, scrolling their list, as long as it holds five rows (--popup-list-min-height: 178px with a mouse, 188px on a touch screen). With less they flip to the other side, and they open beside the trigger only when neither side holds five rows. - 0.103.4 · FixedFrame insets (
Popover,DropdownMenu,ContextMenu,Select,Combobox,ComboboxSelect,Tooltip,PreviewCard,CoachMark,NotificationCenter,MobileNavServerPopover,ToastPositioner,ComposerSuggestionList):--raft-frame-inset-startand--raft-frame-inset-endare the corners of the window's top band (--raft-frame-inset-top), not columns down its sides. A popup anchored under the band keeps its own padding from the window's edge; only one anchored in the band (a title-bar control, or a context menu opened in the bar) keeps 8px clear of a corner. - 0.103.3 · FixedFrame insets (
useFrameInsets,frameCollisionBoundary): opening a positioned popup (Popover,DropdownMenu,Select,Combobox,ComboboxSelect,ContextMenu,Tooltip,PreviewCard,NotificationCenter,MobileNavServerPopover,ComposerSuggestionList) no longer stalls the main thread when--raft-frame-inset-*holds acalc()orenv(titlebar-area-*)expression on an overlay title bar. - 0.10.0 · Breaking ChangesField frames (
Input,Textarea,InputGroup,Select,Combobox,ComboboxSelect,Composer, optionCard,SearchTrigger) are drawn at 1px inline-fieldinstead of 1.5px, on the phone too. - 0.5.37 · FixedBrutal
Comboboxkeeps its shadow when open, asSelectdoes: the control lifts 1px withshadow-raft-mdinstead of dropping the shadow. In Brutal,SelectContentandComboboxContentnow defaultsideOffsetto 8px (was 4px), so the open trigger's shadow stays clear of the popup instead of running into it. Elegant keeps 4px; an explicitsideOffsetstill wins. - 0.1.0 · AddedExtended
Lightboxwith thumbnail strip and related chrome parts; addedComboboxTriggerCountandContextMenuPopup.