Combobox
Anatomy
Section titled “Anatomy”<ComboBox> <ComboBoxTrigger /> <ComboBoxContent> <ComboBoxMenu> <ComboBoxMenuItem /> </ComboBoxMenu> <ComboBoxSeparator /> <ComboBoxLabel /> <ComboBoxItem /> </ComboBoxContent></ComboBox>To display a filterable list of menu items, compose <ComboBox>, <ComboBoxTrigger>, <ComboBoxContent>, <ComboBoxMenu>, and one or more of <ComboBoxMenuItem>.
import { Button } from "stylus-ui/Button";import { ComboBox, ComboBoxTrigger, ComboBoxContent, ComboBoxMenu, ComboBoxMenuItem,} from "stylus-ui/ComboBox";
const options = [ { value: 1, label: "John Doe" }, { value: 2, label: "Jane Smith" }, { value: 3, label: "Robert Johnson" }, { value: 4, label: "Alice Williams" }, { value: 5, label: "Charlie Brown" },];
export default () => ( <ComboBox> <ComboBoxTrigger asChild> <Button variant="secondary" dropdown> Select Teammate </Button> </ComboBoxTrigger> <ComboBoxContent> <ComboBoxMenu> {options.map((option) => ( <ComboBoxMenuItem {...option} key={option.value}> {option.label} </ComboBoxMenuItem> ))} </ComboBoxMenu> </ComboBoxContent> </ComboBox>);Multiple menus
Section titled “Multiple menus”You can include more than one <ComboBoxMenu> in the dropdown. When including multiple menus, it’s helpful to also include <ComboBoxLabel> and <ComboBoxSeparator>. To prevent a menu from displaying a search input, use isSearchable={false}.
import { Button } from "stylus-ui/Button";import { ComboBox, ComboBoxTrigger, ComboBoxContent, ComboBoxLabel, ComboBoxMenu, ComboBoxMenuItem, ComboBoxSeparator,} from "stylus-ui/ComboBox";
const teammates = [ { value: 1, label: "John Doe" }, { value: 2, label: "Jane Smith" }, { value: 3, label: "Robert Johnson" }, { value: 4, label: "Alice Williams" }, { value: 5, label: "Charlie Brown" },];
const timeframes = [ { value: "last_7_days", label: "Last 7 Days" }, { value: "last_30_days", label: "Last 30 Days" }, { value: "last_3_months", label: "Last 3 Months" }, { value: "last_12_months", label: "Last 12 Months" },];
export default () => ( <ComboBox> <ComboBoxTrigger asChild> <Button variant="secondary" dropdown> Select Teammate </Button> </ComboBoxTrigger> <ComboBoxContent> <ComboBoxMenu> {teammates.map((option) => ( <ComboBoxMenuItem {...option} key={option.value}> {option.label} </ComboBoxMenuItem> ))} </ComboBoxMenu> <ComboBoxSeparator /> <ComboBoxLabel>Timeframe</ComboBoxLabel> <ComboBoxMenu isSearchable={false}> {timeframes.map((option) => ( <ComboBoxMenuItem {...option} key={option.value}> {option.label} </ComboBoxMenuItem> ))} </ComboBoxMenu> </ComboBoxContent> </ComboBox>);Non-filterable actions
Section titled “Non-filterable actions”Add extra items outside the scope of menu filters by using <ComboBoxItem>. Use a <ComboBoxSeparator> to visually distinguish sections.
import { Button } from "stylus-ui/Button";import { ComboBox, ComboBoxTrigger, ComboBoxContent, ComboBoxItem, ComboBoxMenu, ComboBoxMenuItem, ComboBoxSeparator,} from "stylus-ui/ComboBox";import { faUserPlus } from "@fortawesome/pro-regular-svg-icons";
const options = [ { value: 1, label: "John Doe" }, { value: 2, label: "Jane Smith" }, { value: 3, label: "Robert Johnson" }, { value: 4, label: "Alice Williams" }, { value: 5, label: "Charlie Brown" },];
export default () => ( <ComboBox> <ComboBoxTrigger asChild> <Button variant="secondary" dropdown> Select Teammate </Button> </ComboBoxTrigger> <ComboBoxContent> <ComboBoxMenu> {options.map((option) => ( <ComboBoxMenuItem {...option} key={option.value}> {option.label} </ComboBoxMenuItem> ))} </ComboBoxMenu> <ComboBoxSeparator /> <ComboBoxItem icon={faUserPlus}>Invite Teammates</ComboBoxItem> </ComboBoxContent> </ComboBox>);API Reference
Section titled “API Reference”ComboBox
Section titled “ComboBox”Displays an autocomplete input with a list of suggestions. The list of suggestions is displayed in a Popover and extends Radix’s Popover props.
defaultOpen
modal
onOpenChange
open
ComboBoxTrigger
Section titled “ComboBoxTrigger” asChild
ComboBoxSeparator
Section titled “ComboBoxSeparator” asChild
ComboBoxContent
Section titled “ComboBoxContent”CombobBox content wrapper. It extends Radix’s PopoverContent and adds a theme prop.
align
alignOffset
arrowPadding
asChild
avoidCollisions
children
Content (e.g. ComboBoxInput, ComboBoxItem list).
collisionBoundary
collisionPadding
container
forceMount
Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries.
hideWhenDetached
onCloseAutoFocus
Event handler called when auto-focusing on close. Can be prevented.
onEscapeKeyDown
Event handler called when the escape key is down. Can be prevented.
onFocusOutside
Event handler called when the focus moves outside of the DismissableLayer.
Can be prevented.
onInteractOutside
Event handler called when an interaction happens outside the DismissableLayer.
Specifically, when a pointerdown event happens outside or focus moves outside of it.
Can be prevented.
onOpenAutoFocus
Event handler called when auto-focusing on open. Can be prevented.
onPointerDownOutside
Event handler called when the a pointerdown event happens outside of the DismissableLayer.
Can be prevented.
side
sideOffset
sticky
theme
Background and text theme for the dropdown panel.
updatePositionStrategy
ComboBoxMenuItemBase
Section titled “ComboBoxMenuItemBase”Base component for ComboBox items. It can be used to display a list of options based off of menuType, icon, showAvatar, and avatarProps.
avatarProps
childrenClassName
disabled
icon
iconClassName
shortcutText
showAvatar
showShortcut
showTag
subtext
subtextProps
tagComponent
variant
ComboBoxMenuItem
Section titled “ComboBoxMenuItem”Menu item for the ComboBox. It can be used to display a list of options based off of menuType.
value
avatarProps
checked
childrenClassName
disabled
icon
iconClassName
menuType
onItemKeyDown
onItemSelect
shortcutText
showAvatar
showShortcut
showTag
subtext
subtextProps
tagComponent
variant
ComboBoxItem
Section titled “ComboBoxItem”Item for the ComboBox. It can be used to display a call to action or item that is outside of ComboBoxMenu.
avatarProps
childrenClassName
disabled
icon
iconClassName
shortcutText
showAvatar
showShortcut
showTag
subtext
subtextProps
tagComponent
variant
ComboBoxMenu
Section titled “ComboBoxMenu”An autocomplete input and command palette with a list of suggestions.
className
handleInputChange
isLoading
isSearchable
menuType
noResultsText
onOptionSelect
onValueChange
placeholder
scrollAreaChildren
theme
ComboBoxLabel
Section titled “ComboBoxLabel”A label for a ComboBox. It isn’t focusable.