Primitiveselection

Combobox

Stable

Campo em que a pessoa digita até a lista, com grupos, limpeza e seleção múltipla em chips. Composto sobre Base UI Combobox e sobre o InputGroup e o Button do Up Web DS. O Select mostra uma lista; o combobox deixa digitar dentro dela — o que só compensa depois do ponto em que varrer com os olhos para de funcionar, e cobra um preço real: o campo passa a aceitar texto que não casa com nada, então o estado vazio faz parte do contrato.

Instalação

npx up-web-ds add combobox

Gera check, chevron-down, close para a biblioteca de ícones do projeto (components.json → iconLibrary).

Preview

Basic

Default

Grouped

With Clear

Multiple

All states

Basic

Default

Grouped

With Clear

Multiple

Usage

@/components/ui/combobox
import {
  Combobox,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
} from '@/components/ui/combobox'
Combobox
<Combobox>
  <ComboboxInput
    aria-label="Buscar um primitive"
    className="w-full max-w-xs"
    placeholder="Buscar um primitive"
  />

  <ComboboxContent>
    <ComboboxEmpty>Nenhum item com esse nome.</ComboboxEmpty>

    <ComboboxList>
      <ComboboxItem value="button">button</ComboboxItem>
      <ComboboxItem value="dialog">dialog</ComboboxItem>
      <ComboboxItem value="select">select</ComboboxItem>
    </ComboboxList>
  </ComboboxContent>
</Combobox>

Props

Combobox

Props de Combobox
PropTypeDefaultDescription
actionsRefReact.RefObject<AriaCombobox.Actions | null>sem valor padrãoA ref to imperative actions. - `unmount`: Manually unmounts the combobox. Call this after any externally controlled closing animation finishes.
autoCompletestringsem valor padrãoProvides a hint to the browser for autofill.
autoHighlightbooleanfalseWhether the first matching item is highlighted automatically while filtering.
childrenReact.ReactNodesem valor padrão
defaultInputValuestring | number | readonly string[]sem valor padrãoThe uncontrolled input value when initially rendered. To render a controlled input, use the `inputValue` prop instead.
defaultOpenbooleanfalseWhether the popup is initially open. To render a controlled popup, use the `open` prop instead.
defaultValueComboboxValueType<Value, Multiple> | nullsem valor padrãoThe uncontrolled selected value of the combobox when it's initially rendered. To render a controlled combobox, use the `value` prop instead.
disabledbooleanfalseWhether the component should ignore user interaction.
filter((itemValue: Value, query: string, itemToString?: ((itemValue: Value) => string) | undefined) => boolean) | nullsem valor padrãoFilter function used to match items vs input query.
filteredItemsreadonly any[] | readonly Group<any>[]sem valor padrãoFiltered items to display in the list. When provided, the list will use these items instead of filtering the `items` prop internally. Use when you want to control filtering logic externally with the `useFilter()` hook.
formstringsem valor padrãoIdentifies the form that owns the internal input. Useful when the combobox is rendered outside the form.
gridbooleanfalseWhether list items are presented in a grid layout. When enabled, arrow keys navigate across rows and columns inferred from DOM rows.
highlightItemOnHoverbooleantrueWhether moving the pointer over items should highlight them. Disabling this prop allows CSS `:hover` to be differentiated from the `:focus` (`data-highlighted`) state.
idstringsem valor padrãoThe id of the component.
inlinebooleanfalseWhether the list is rendered inline without using the component's own popup. Specify `open` unconditionally in conjunction with this prop so the list is considered visible: `<Combobox.Root inline open>` In a `Combobox.Root` > `Dialog.Root` composition, bind the Combobox's `open` and `onOpenChange` props to the `Dialog`'s `open` and `onOpenChange` state instead so the component resets its transient state (filter query, highlighted item, and input value) when the dialog closes.
inputRefReact.Ref<HTMLInputElement>sem valor padrãoA ref to the hidden input element.
inputValuestring | number | readonly string[]sem valor padrãoThe input value of the combobox. Use when controlled.
isItemEqualToValue((itemValue: Value, value: Value) => boolean)sem valor padrãoCustom comparison logic used to determine if a combobox item value matches the current selected value. Useful when item values are objects without matching referentially. Defaults to `Object.is` comparison.
itemsreadonly any[] | readonly Group<any>[]sem valor padrãoThe items to be displayed in the list. Can be either a flat array of items or an array of groups with items.
itemToStringLabel((itemValue: Value) => string)sem valor padrãoWhen the item values are objects (`<Combobox.Item value={object}>`), this function converts the object value to a string representation for display in the input. If the shape of the object is `{ value, label }`, the label will be used automatically without needing to specify this prop.
itemToStringValue((itemValue: Value) => string)sem valor padrãoWhen the item values are objects (`<Combobox.Item value={object}>`), this function converts the object value to a string representation for form submission. If the shape of the object is `{ value, label }`, the value will be used automatically without needing to specify this prop.
limitnumber-1The maximum number of items to display in the list.
localeIntl.LocalesArgumentsem valor padrãoThe locale to use for string comparison. Defaults to the user's runtime locale.
loopFocusbooleantrueWhether to loop keyboard focus back to the input when the end of the list is reached while using the arrow keys. The first item can then be reached by pressing <kbd>ArrowDown</kbd> again from the input, or the last item can be reached by pressing <kbd>ArrowUp</kbd> from the input. The input is always included in the focus loop per [ARIA Authoring Practices](https://www.w3.org/WAI/ARIA/apg/patterns/combobox/). When disabled, focus does not move when on the last element and the user presses <kbd>ArrowDown</kbd>, or when on the first element and the user presses <kbd>ArrowUp</kbd>.
modalbooleanfalseDetermines if the popup enters a modal state when open. - `true`: user interaction is limited to the popup: document page scroll is locked and pointer interactions on outside elements are disabled. - `false`: user interaction with the rest of the document is allowed. On touch devices, a `true` modal blocks outside taps but leaves the page scrollable unless the popup spans nearly the full viewport width, matching native iOS behavior.
multipleMultiplefalseWhether multiple items can be selected.
namestringsem valor padrãoIdentifies the field when a form is submitted.
onInputValueChange((inputValue: string, eventDetails: ComboboxRoot.ChangeEventDetails) => void)sem valor padrãoEvent handler called when the input value changes.
onItemHighlighted((highlightedValue: Value | undefined, eventDetails: ComboboxRoot.HighlightEventDetails) => void)sem valor padrãoCallback fired when an item is highlighted or unhighlighted. Receives the highlighted item value (or `undefined` if no item is highlighted) and event details with a `reason` property describing why the highlight changed. The `reason` can be: - `'keyboard'`: the highlight changed due to keyboard navigation. - `'pointer'`: the highlight changed due to pointer hovering. - `'none'`: the highlight changed programmatically.
onOpenChange((open: boolean, eventDetails: ComboboxRoot.ChangeEventDetails) => void)sem valor padrãoEvent handler called when the popup is opened or closed.
onOpenChangeComplete((open: boolean) => void)sem valor padrãoEvent handler called after any animations complete when the popup is opened or closed.
onValueChange((value: ComboboxValueType<Value, Multiple> | (Multiple extends true ? never : null), eventDetails: ComboboxRoot.ChangeEventDetails) => void)sem valor padrãoEvent handler called when the selected value of the combobox changes.
openbooleansem valor padrãoWhether the popup is currently open. Use when controlled.
openOnInputClickbooleantrueWhether the popup opens when clicking the input.
readOnlybooleanfalseWhether the user should be unable to choose a different option from the popup.
requiredbooleanfalseWhether the user must choose a value before submitting a form.
valueComboboxValueType<Value, Multiple> | nullsem valor padrãoThe selected value of the combobox. Use when controlled.
virtualizedbooleanfalseWhether the items are being externally virtualized.

Estende ComboboxRoot.Props<Value, Multiple>.

ComboboxValue

Props de ComboboxValue
PropTypeDefaultDescription
childrenReact.ReactNode | ((selectedValue: any) => React.ReactNode)sem valor padrão
placeholderReact.ReactNodesem valor padrãoThe placeholder value to display when no value is selected. This is overridden by `children` if specified, or by a null item's label in `items`.

Estende ComboboxPrimitive.Value.Props.

ComboboxTrigger

Props de ComboboxTrigger
PropTypeDefaultDescription
classNamestring | ((state: ComboboxTriggerState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
disabledbooleanfalseWhether the component should ignore user interaction.
nativeButtonbooleantrueWhether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`).
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ComboboxTriggerState>sem valor padrãoAllows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
styleReact.CSSProperties | ((state: ComboboxTriggerState) => React.CSSProperties | undefined)sem valor padrãoStyle applied to the element, or a function that returns a style object based on the component's state.

Estende ComboboxPrimitive.Trigger.Props. Aceita também os atributos padrão de um elemento React (284 não listados).

ComboboxInput

Props de ComboboxInput
PropTypeDefaultDescription
showClearbooleanfalse
showTriggerbooleantrue
classNamestring | ((state: ComboboxInputState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
disabledbooleanfalseWhether the component should ignore user interaction.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ComboboxInputState>sem valor padrãoAllows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
styleReact.CSSProperties | ((state: ComboboxInputState) => React.CSSProperties | undefined)sem valor padrãoStyle applied to the element, or a function that returns a style object based on the component's state.

Estende ComboboxPrimitive.Input.Props. Aceita também os atributos padrão de um elemento React (304 não listados).

ComboboxContent

Props de ComboboxContent
PropTypeDefaultDescription
alignAlign'start'How to align the popup relative to the specified side.
alignOffsetnumber | OffsetFunction0Additional offset along the alignment axis in pixels. Also accepts a function that returns the offset to read the dimensions of the anchor and positioner elements, along with its side and alignment. The function takes a `data` object parameter with the following properties: - `data.anchor`: the dimensions of the anchor element with properties `width` and `height`. - `data.positioner`: the dimensions of the positioner element with properties `width` and `height`. - `data.side`: which side of the anchor element the positioner is aligned against. - `data.align`: how the positioner is aligned relative to the specified side.
anchorElement | VirtualElement | React.RefObject<Element | null> | (() => Element | VirtualElement | null) | nullsem valor padrãoAn element to position the popup against. By default, the popup will be positioned against the trigger.
classNamestring | ((state: ComboboxPopupState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
finalFocusboolean | React.RefObject<HTMLElement | null> | ((closeType: InteractionType) => void | boolean | HTMLElement | null)sem valor padrãoDetermines the element to focus when the popup is closed. - `false`: Do not move focus. - `true`: Move focus based on the default behavior (trigger or previously focused element). - `RefObject`: Move focus to the ref element. - `function`: Called with the interaction type (`mouse`, `touch`, `pen`, or `keyboard`). Return an element to focus, `true` to use the default behavior, or `false`/`undefined` to do nothing.
initialFocusboolean | React.RefObject<HTMLElement | null> | ((openType: InteractionType) => void | boolean | HTMLElement | null)sem valor padrãoDetermines the element to focus when the popup is opened. - `false`: Do not move focus. - `true`: Move focus based on the default behavior (first tabbable element or popup). - `RefObject`: Move focus to the ref element. - `function`: Called with the interaction type (`mouse`, `touch`, `pen`, or `keyboard`). Return an element to focus, `true` to use the default behavior, or `false`/`undefined` to do nothing.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ComboboxPopupState>sem valor padrãoAllows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
sideSide'bottom'Which side of the anchor element to align the popup against. May automatically change to avoid collisions.
sideOffsetnumber | OffsetFunction6Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment. The function takes a `data` object parameter with the following properties: - `data.anchor`: the dimensions of the anchor element with properties `width` and `height`. - `data.positioner`: the dimensions of the positioner element with properties `width` and `height`. - `data.side`: which side of the anchor element the positioner is aligned against. - `data.align`: how the positioner is aligned relative to the specified side.
styleReact.CSSProperties | ((state: ComboboxPopupState) => React.CSSProperties | undefined)sem valor padrãoStyle applied to the element, or a function that returns a style object based on the component's state.

Estende ComboboxPrimitive.Popup.Props & Pick< ComboboxPrimitive.Positioner.Props, 'side' | 'align' | 'sideOffset' | 'alignOffset' | 'anchor' >. Aceita também os atributos padrão de um elemento React (275 não listados).

ComboboxList

Props de ComboboxList
PropTypeDefaultDescription
childrenReact.ReactNode | ((item: any, index: number) => React.ReactNode)sem valor padrão
classNamestring | ((state: ComboboxListState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ComboboxListState>sem valor padrãoAllows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
styleReact.CSSProperties | ((state: ComboboxListState) => React.CSSProperties | undefined)sem valor padrãoStyle applied to the element, or a function that returns a style object based on the component's state.

Estende ComboboxPrimitive.List.Props. Aceita também os atributos padrão de um elemento React (274 não listados).

ComboboxItem

Props de ComboboxItem
PropTypeDefaultDescription
childrenReact.ReactNodesem valor padrão
classNamestring | ((state: ComboboxItemState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
disabledbooleanfalseWhether the component should ignore user interaction.
indexnumbersem valor padrãoThe index of the item in the list. Improves performance when specified by avoiding the need to calculate the index automatically from the DOM.
nativeButtonbooleanfalseWhether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `true` if the rendered element is a native button.
onClick((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void)sem valor padrãoAn optional click handler for the item when selected. It fires when clicking the item with the pointer, as well as when pressing `Enter` with the keyboard if the item is highlighted when the `Input` or `List` element has focus.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ComboboxItemState>sem valor padrãoAllows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
styleReact.CSSProperties | ((state: ComboboxItemState) => React.CSSProperties | undefined)sem valor padrãoStyle applied to the element, or a function that returns a style object based on the component's state.
valueanynullA unique value that identifies this item.

Estende ComboboxPrimitive.Item.Props. Aceita também os atributos padrão de um elemento React (272 não listados).

ComboboxGroup

Props de ComboboxGroup
PropTypeDefaultDescription
classNamestring | ((state: ComboboxGroupState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
itemsreadonly any[]sem valor padrãoItems to be rendered within this group. When provided, child `Collection` components will use these items.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ComboboxGroupState>sem valor padrãoAllows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
styleReact.CSSProperties | ((state: ComboboxGroupState) => React.CSSProperties | undefined)sem valor padrãoStyle applied to the element, or a function that returns a style object based on the component's state.

Estende ComboboxPrimitive.Group.Props. Aceita também os atributos padrão de um elemento React (275 não listados).

ComboboxLabel

Props de ComboboxLabel
PropTypeDefaultDescription
classNamestring | ((state: ComboboxGroupLabelState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ComboboxGroupLabelState>sem valor padrãoAllows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
styleReact.CSSProperties | ((state: ComboboxGroupLabelState) => React.CSSProperties | undefined)sem valor padrãoStyle applied to the element, or a function that returns a style object based on the component's state.

Estende ComboboxPrimitive.GroupLabel.Props. Aceita também os atributos padrão de um elemento React (275 não listados).

ComboboxCollection

Props de ComboboxCollection
PropTypeDefaultDescription
children, obrigatória(item: any, index: number) => React.ReactNodesem valor padrão

Estende ComboboxPrimitive.Collection.Props.

ComboboxEmpty

Props de ComboboxEmpty
PropTypeDefaultDescription
classNamestring | ((state: ComboboxEmptyState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ComboboxEmptyState>sem valor padrãoAllows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
styleReact.CSSProperties | ((state: ComboboxEmptyState) => React.CSSProperties | undefined)sem valor padrãoStyle applied to the element, or a function that returns a style object based on the component's state.

Estende ComboboxPrimitive.Empty.Props. Aceita também os atributos padrão de um elemento React (275 não listados).

ComboboxSeparator

Props de ComboboxSeparator
PropTypeDefaultDescription
classNamestring | ((state: ComboboxSeparatorState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
orientationOrientation'horizontal'The orientation of the separator.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ComboboxSeparatorState>sem valor padrãoAllows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
styleReact.CSSProperties | ((state: ComboboxSeparatorState) => React.CSSProperties | undefined)sem valor padrãoStyle applied to the element, or a function that returns a style object based on the component's state.

Estende ComboboxPrimitive.Separator.Props. Aceita também os atributos padrão de um elemento React (275 não listados).

ComboboxChips

Props de ComboboxChips
PropTypeDefaultDescription
classNamestring | ((state: ComboboxChipsState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ComboboxChipsState>sem valor padrãoAllows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
styleReact.CSSProperties | ((state: ComboboxChipsState) => React.CSSProperties | undefined)sem valor padrãoStyle applied to the element, or a function that returns a style object based on the component's state.

Estende React.ComponentPropsWithRef<typeof ComboboxPrimitive.Chips> & ComboboxPrimitive.Chips.Props. Aceita também os atributos padrão de um elemento React (275 não listados).

ComboboxChip

Props de ComboboxChip
PropTypeDefaultDescription
showRemovebooleantrue
classNamestring | ((state: ComboboxChipState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ComboboxChipState>sem valor padrãoAllows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
styleReact.CSSProperties | ((state: ComboboxChipState) => React.CSSProperties | undefined)sem valor padrãoStyle applied to the element, or a function that returns a style object based on the component's state.

Estende ComboboxPrimitive.Chip.Props. Aceita também os atributos padrão de um elemento React (275 não listados).

ComboboxChipsInput

Props de ComboboxChipsInput
PropTypeDefaultDescription
classNamestring | ((state: ComboboxInputState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
disabledbooleanfalseWhether the component should ignore user interaction.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, ComboboxInputState>sem valor padrãoAllows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
styleReact.CSSProperties | ((state: ComboboxInputState) => React.CSSProperties | undefined)sem valor padrãoStyle applied to the element, or a function that returns a style object based on the component's state.

Estende ComboboxPrimitive.Input.Props. Aceita também os atributos padrão de um elemento React (304 não listados).

prop obrigatória.

Metadata

Notas de acessibilidade

Teclado verificado por teste: ArrowDown abre já com a primeira opção destacada, digitar estreita a lista em vez de exigir rolagem, Enter escolhe a opção destacada e Escape fecha sem tirar o foco do campo. Leitor de tela verificado por teste: o controle tem papel combobox, aria-expanded acompanha o estado, aria-controls aponta para o listbox portalizado, a opção escolhida é marcada por aria-selected, e quando nada casa o estado vazio é anunciado — um campo que aceita texto livre pode receber texto que não casa com nada, e não dizer nada de volta lê como campo quebrado. Em seleção múltipla cada chip é removível sozinho, verificado por teste: corrigir uma escolha entre duas não pode custar a outra. Touch verificado em navegador com emulação de toque em viewport de 375px: campo, opções e o botão de remover chip medem acima do mínimo de 24x24 da WCAG 2.2 SC 2.5.8, e o popup cabe na viewport. Reduced motion verificado com prefers-reduced-motion: reduce — os tokens de motion colapsam para 1ms e a animação de entrada do popup mede 0.001s.

Classificação

Layer
Primitive
Domínio
Domain-free (compartilhado)
Categoria
selection
Status
Stable

Origem e distribuição

Fonte
shadcn registry / combobox
Licença
MIT
Distribuição
Interna

Acessibilidade

  • Teclado: revisado
  • Leitor de tela: revisado
  • Touch: revisado
  • Reduced motion: revisado

Dependências

Pacotes
@base-ui/react
Ícones
check, chevron-down, close
Construído sobre
Input GroupButton
Usado por
Nenhum ainda