Selection & Dates
@hacline/ui/comboboxCombobox
Search by keyword and select one or more options.
Usage
Type a keyword in "Team", navigate with the arrow keys, and press Enter to select. Each dropdown item uses value for the submitted value and label to display the team name.
"use client";
import {
Combobox,
ComboboxContent,
ComboboxEmpty,
ComboboxInput,
ComboboxLabel,
ComboboxList,
} from "@/components/ui/hacline/components/combobox";
const teams = [
{ label: "Interaction Design", value: "design" },
{ label: "Frontend Engineering", value: "frontend" },
{ label: "Site Operations", value: "ops" },
];
export const Example = () => (
<div className="grid w-full max-w-xs gap-2">
<Combobox defaultValue="design" items={teams} name="team">
<ComboboxLabel>Team</ComboboxLabel>
<ComboboxInput placeholder="Search teams" />
<ComboboxContent>
<ComboboxEmpty>No matching teams</ComboboxEmpty>
<ComboboxList />
</ComboboxContent>
</Combobox>
</div>
);Multiple Selection and Chip Removal
Enable multiple and render selected chips with ComboboxValue. Each chip's remove button stays synchronized with the selection state.
Docs
"use client";
import {
Combobox,
ComboboxChip,
ComboboxChipRemove,
ComboboxChips,
ComboboxContent,
ComboboxInput,
ComboboxLabel,
ComboboxList,
ComboboxValue,
} from "@/components/ui/hacline/components/combobox";
const labels = ["Frontend", "Docs", "Accessibility"];
export const Example = () => (
<div className="grid w-full max-w-xs gap-2">
<Combobox defaultValue={["Docs"]} items={labels} multiple name="labels">
<ComboboxLabel>Task labels</ComboboxLabel>
<ComboboxChips>
<ComboboxValue>
{({ value }) =>
(Array.isArray(value) ? value : []).map((entry: string) => (
<ComboboxChip key={entry} value={entry}>
{entry}
<ComboboxChipRemove aria-label={`Remove ${entry}`} />
</ComboboxChip>
))
}
</ComboboxValue>
<ComboboxInput className="flex-1 border-0" placeholder="Add label" />
</ComboboxChips>
<ComboboxContent>
<ComboboxList />
</ComboboxContent>
</Combobox>
</div>
);Parts
| Part | Description | Extended Props |
|---|---|---|
ComboboxArrow | An arrow on the popup's edge that points at the input. | — |
ComboboxChip | One selected value. Without children, it shows the value's label. | — |
ComboboxChipRemove | A button inside a chip that removes its value. Name it with aria-label. | — |
ComboboxChips | The selected values as chips, around the input. | — |
ComboboxChipsOverflow | How many chips don't fit on the chips' line, once some collapse. Rendering it inside ComboboxChips turns collapsing on. Without children, "+2 more". | — |
ComboboxClear | A button that empties the input and selects nothing. Shown while there's something to clear. | — |
ComboboxContent | The popup that holds the list, positioned against the input. | — |
ComboboxCreate | An option that creates an item from the input's text. Shown while the text matches no item's label exactly. | — |
ComboboxEmpty | Shown while no item matches. Its message is announced when it appears. | — |
ComboboxGroup | A group of items, named by its ComboboxGroupLabel, and hidden while none of its items shows. | — |
ComboboxGroupLabel | The group's heading, which names the group. | — |
ComboboxInput | The text input that filters the list and holds the chosen item's label. | size |
ComboboxItem | An option. Pressing it selects it, or toggles it with multiple. | — |
ComboboxItemIcon | An icon inside an item. ComboboxValueIcon shows the selected item's next to the input. Screen readers, typeahead and filtering skip it, and mirror flips it in right-to-left text. | — |
ComboboxItemIndicator | The check inside a selected item. Rendered while it's selected, or always with keepMounted. | — |
ComboboxItems | Renders data items. Used by data comboboxes, and available for custom layouts. | — |
ComboboxItemText | The item's text, with the part the input's text matched in <mark>. Without string content, it shows the item's label. | — |
ComboboxLabel | A visible label for the input. | — |
ComboboxList | The listbox. Without children, it renders the combobox's items, filtered. | — |
ComboboxSelectAll | An option that selects every item that matches, with multiple: in its group inside a ComboboxGroup, or in the whole list. | — |
ComboboxSeparator | A line between items or groups, hidden from screen readers. | — |
ComboboxStatus | A polite live region for loading and result counts. Its content is yours, usually a function of its state. | — |
ComboboxTrigger | A button that opens and closes the list, out of the tab order. | size |
ComboboxValue | The selected value, as a function of its state, like one chip per value. Without children, the labels joined with commas, or "France, Chile and 2 more" with maxLabels. Renders no element of its own. | — |
ComboboxValueIcon | The selected item's icon, copied from its ComboboxItemIcon, like next to the input. Rendered while one item is selected and it has an icon. | — |
Props
Prop
Type