Primitiveselection

Select

Stable

Campo de seleção com trigger, popup em listbox, grupos, rótulos e separadores. Composto sobre Base UI Select; a escolha é reportada pelo rótulo do item, não pelo valor bruto.

Instalação

npx up-web-ds add select

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

Preview

Basic

Default

Camada

With Value

StatusTudo que a ingestão gera nasce como Incoming.

Grouped

Origem

Sizes

Camada (sm)
Camada (default)

Disabled

DomínioPrimitives são domain-free, então o campo não se aplica.

With Disabled Item

DistribuiçãoRestricted exige revisão de licença antes de ser oferecido.

Invalid

CamadaEscolha uma camada para continuar.

Scrollable

Papel de ícone

All states

Basic

Default

Camada

With Value

StatusTudo que a ingestão gera nasce como Incoming.

Grouped

Origem

Sizes

Camada (sm)
Camada (default)

Disabled

DomínioPrimitives são domain-free, então o campo não se aplica.

With Disabled Item

DistribuiçãoRestricted exige revisão de licença antes de ser oferecido.

Invalid

CamadaEscolha uma camada para continuar.

Scrollable

Papel de ícone

Usage

@/components/ui/select
import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue,
} from '@/components/ui/select'
Select
<Select>
  <SelectTrigger className="w-56" aria-label="Camada">
    <SelectValue placeholder="Selecione uma camada" />
  </SelectTrigger>

  <SelectContent>
    <SelectItem value="primitive">Primitive</SelectItem>
    <SelectItem value="recipe">Recipe</SelectItem>
    <SelectItem value="component">Component</SelectItem>
  </SelectContent>
</Select>

Props

Select

Props de Select
PropTypeDefaultDescription
actionsRefReact.RefObject<SelectRootActions | null>sem valor padrãoA ref to imperative actions. - `unmount`: Manually unmounts the select. Call this after any externally controlled closing animation finishes.
autoCompletestringsem valor padrãoProvides a hint to the browser for autofill.
childrenReact.ReactNodesem valor padrão
defaultOpenbooleanfalseWhether the select popup is initially open. To render a controlled select popup, use the `open` prop instead.
defaultValueSelectValueType<Value, Multiple> | nullsem valor padrãoThe uncontrolled value of the select when it's initially rendered. To render a controlled select, use the `value` prop instead.
disabledbooleanfalseWhether the component should ignore user interaction.
formstringsem valor padrãoIdentifies the form that owns the hidden input. Useful when the select is rendered outside the form.
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 Select.
inputRefReact.Ref<HTMLInputElement>sem valor padrãoA ref to access the hidden input element.
isItemEqualToValue((itemValue: Value, value: Value) => boolean)sem valor padrãoCustom comparison logic used to determine if a select item value matches the current selected value. Useful when item values are objects without matching referentially. Defaults to `Object.is` comparison.
itemsreadonly Group<any>[] | Record<string, React.ReactNode> | readonly { label: React.ReactNode; value: any; }[]sem valor padrãoData structure of the items rendered in the select popup. When specified, `<Select.Value>` renders the label of the selected item instead of the raw value.
itemToStringLabel((itemValue: Value) => string)sem valor padrãoWhen the item values are objects (`<Select.Item value={object}>`), this function converts the object value to a string representation for display in the trigger. 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 (`<Select.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.
modalbooleantrueDetermines if the select enters a modal state when open. - `true`: user interaction is limited to the select: 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.
onOpenChange((open: boolean, eventDetails: SelectRootChangeEventDetails) => void)sem valor padrãoEvent handler called when the select popup is opened or closed.
onOpenChangeComplete((open: boolean) => void)sem valor padrãoEvent handler called after any animations complete when the select popup is opened or closed.
onValueChange((value: SelectValueType<Value, Multiple> | (Multiple extends true ? never : null), eventDetails: SelectRootChangeEventDetails) => void)sem valor padrãoEvent handler called when the value of the select changes.
openbooleansem valor padrãoWhether the select popup is currently open.
readOnlybooleanfalseWhether the user should be unable to choose a different option from the select popup.
requiredbooleanfalseWhether the user must choose a value before submitting a form.
valueSelectValueType<Value, Multiple> | nullsem valor padrãoThe value of the select. Use when controlled.

Estende SelectRoot.Props<Value, Multiple>.

SelectGroup

Props de SelectGroup
PropTypeDefaultDescription
classNamestring | ((state: SelectGroupState) => 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, SelectGroupState>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: SelectGroupState) => 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 SelectPrimitive.Group.Props. Aceita também os atributos padrão de um elemento React (275 não listados).

SelectValue

Props de SelectValue
PropTypeDefaultDescription
childrenReact.ReactNode | ((value: any) => React.ReactNode)sem valor padrãoAccepts a function that returns a `ReactNode` to format the selected value.
classNamestring | ((state: SelectValueState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
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`.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectValueState>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: SelectValueState) => 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 SelectPrimitive.Value.Props. Aceita também os atributos padrão de um elemento React (274 não listados).

SelectTrigger

Props de SelectTrigger
PropTypeDefaultDescription
size"default" | "sm"'default'
childrenReact.ReactNodesem valor padrão
classNamestring | ((state: SelectTriggerState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
disabledbooleansem valor padrãoWhether 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, SelectTriggerState>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: SelectTriggerState) => 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 SelectPrimitive.Trigger.Props. Aceita também os atributos padrão de um elemento React (283 não listados).

SelectContent

Props de SelectContent
PropTypeDefaultDescription
alignAlign'center'How to align the popup relative to the specified side.
alignItemWithTriggerbooleantrueWhether the positioner overlaps the trigger so the selected item's text is aligned with the trigger's value text. This only applies to mouse input and is automatically disabled if there is not enough space.
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.
childrenReact.ReactNodesem valor padrão
classNamestring | ((state: SelectPopupState) => 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) => boolean | HTMLElement | null | void)sem valor padrãoDetermines the element to focus when the select 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.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectPopupState>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 | OffsetFunction4Distance 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: SelectPopupState) => 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 SelectPrimitive.Popup.Props & Pick< SelectPrimitive.Positioner.Props, 'align' | 'alignOffset' | 'side' | 'sideOffset' | 'alignItemWithTrigger' >. Aceita também os atributos padrão de um elemento React (274 não listados).

SelectLabel

Props de SelectLabel
PropTypeDefaultDescription
classNamestring | ((state: SelectGroupLabelState) => 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, SelectGroupLabelState>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: SelectGroupLabelState) => 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 SelectPrimitive.GroupLabel.Props. Aceita também os atributos padrão de um elemento React (275 não listados).

SelectItem

Props de SelectItem
PropTypeDefaultDescription
childrenReact.ReactNodesem valor padrão
classNamestring | ((state: SelectItemState) => 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.
labelstringsem valor padrãoSpecifies the text label to use when the item is matched during keyboard text navigation. Defaults to the item text content if not provided.
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.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectItemState>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: SelectItemState) => 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 select item.

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

SelectSeparator

Props de SelectSeparator
PropTypeDefaultDescription
classNamestring | ((state: SelectSeparatorState) => 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, SelectSeparatorState>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: SelectSeparatorState) => 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 SelectPrimitive.Separator.Props. Aceita também os atributos padrão de um elemento React (275 não listados).

SelectScrollUpButton

Props de SelectScrollUpButton
PropTypeDefaultDescription
classNamestring | ((state: SelectScrollUpArrowState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
keepMountedbooleanfalseWhether to keep the HTML element in the DOM while the select popup is not scrollable.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectScrollUpArrowState>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: SelectScrollUpArrowState) => 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.ComponentProps<typeof SelectPrimitive.ScrollUpArrow>. Aceita também os atributos padrão de um elemento React (275 não listados).

SelectScrollDownButton

Props de SelectScrollDownButton
PropTypeDefaultDescription
classNamestring | ((state: SelectScrollDownArrowState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
keepMountedbooleanfalseWhether to keep the HTML element in the DOM while the select popup is not scrollable.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, SelectScrollDownArrowState>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: SelectScrollDownArrowState) => 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.ComponentProps<typeof SelectPrimitive.ScrollDownArrow>. Aceita também os atributos padrão de um elemento React (275 não listados).

Composition

Trigger e content são irmãos dentro do Select, que é quem guarda o valor. O SelectValue vive no gatilho porque é lá que o valor escolhido aparece.

Composição de Select

Select

  • SelectTrigger
    • SelectValue
  • SelectContent
    • SelectScrollUpButton
    • SelectGroup
      • SelectLabel
      • SelectItem
    • SelectSeparator
    • SelectScrollDownButton

Metadata

Notas de acessibilidade

Teclado verificado por teste: ArrowDown abre e percorre a lista, ArrowUp volta, Enter escolhe o item destacado, Escape desiste sem alterar o valor, e o foco retorna ao trigger nos dois desfechos. Um select desabilitado sai da ordem de tabulação, e um item desabilitado continua anunciado sem poder ser escolhido. Leitor de tela verificado em navegador: o trigger é um combobox nomeado pelo rótulo do campo, aria-expanded acompanha o estado, o popup portalizado é ligado por aria-controls e expõe options com a seleção atual marcada; a escolha é reportada pelo rótulo do item, não pelo valor bruto, e aria-invalid é exposto sem trocar o papel do controle. Touch verificado em viewport de 375px com emulação de toque: o trigger e cada opção medem acima do mínimo de 24x24 da WCAG 2.2 SC 2.5.8, e abrir e escolher funcionam por toque. 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, sem perder a abertura nem a escolha.

Classificação

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

Origem e distribuição

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

Acessibilidade

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

Dependências

Pacotes
Nenhuma
Ícones
check, chevron-down, chevron-up
Construído sobre
Nenhum
Usado por
Nenhum ainda