Ir al contenido
Español

Cómo funciona

The text in the field is the query. Matching tries a plain substring first, then letters in order ("nyk" finds New York), and ranks contiguous runs higher. On close the field returns to the chosen label, so a half-typed query never stands in for a value. The panel is not portaled, so it stays put inside dialogs and scroll areas.

Úsalo para

  • Choosing one value from a long list people know by name: a city, a person, a project.
  • When typing is faster than scrolling, on desktop and mobile alike.

Busca otra opción cuando

  • Under eight options: use a select or radio group.
  • Several values: use a multi-select or tags input.
  • Running commands: use a command palette.

Uso

import { useState } from 'react'
import { Combobox } from './Combobox.jsx'

const cities = [
  { value: 'lis', label: 'Lisbon', description: 'UTC+0' },
  { value: 'sgp', label: 'Singapore', description: 'UTC+8' },
  { value: 'tyo', label: 'Tokyo', description: 'UTC+9' },
]

export function ZoneField() {
  const [zone, setZone] = useState(null)
  return (
    <>
      <label htmlFor="zone">Time zone</label>
      <Combobox id="zone" options={cities} value={zone} onChange={setZone} placeholder="Search a city" />
    </>
  )
}

Propiedades

PropiedadTipoPor defectoQué hace
options{ value, label, description?, disabled? }[]—The options; value must be unique. label is what is matched and shown in the field.
valuestring | number | null—Controlled value; null means nothing chosen.
defaultValuestring | number | nullnullInitial value when uncontrolled.
onChange(value, option) => void—Called when an option is chosen, or with nulls when Esc clears a closed field.
placeholderstring'Search'Hint in the empty field.
renderOption(option) => ReactNode—Leading content for each row, such as an avatar or badge.
emptyTextstring—Text when nothing matches; defaults to labels.noMatch.
disabledbooleanfalseDisables the field.
invalidbooleanfalseDanger outline and aria-invalid.
labelsobject—Replaces built-in text: noMatch, results(n), toggle.
...restHTMLAttributes<HTMLDivElement>—Go to the root; id and aria-label / labelledby / describedby go to the input. List height: --ds-combo-list-height (248px); layer: --ds-combo-z (30).

Accesibilidad

  • Follows the ARIA 1.2 combobox pattern with list autocomplete: the input has role="combobox", aria-expanded, aria-controls and aria-activedescendant; the list is a listbox with aria-selected options.
  • Keyboard: Down / Up open and move (skipping disabled rows), Alt+Up closes, Home / End jump when not searching, Enter chooses, Esc closes or, when closed, clears, Tab closes.
  • The number of results is announced in a polite live region while searching.
  • Matches are shown by weight and a tint, not colour alone. Rows are 40px, 44px on touch. Reduced motion removes the panel and check animations.

Movimiento

The panel enters in 220ms ease-out from 6px above and scale 0.96. The field turns white with a halo over 220ms; the chevron turns in 240ms. The check on the chosen row pops with a 320ms spring.

Añádelo a tu proyecto

Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.

Combobox.jsxcombobox.csstokens.cssREADME.md

Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

Formularios
Cuadrícula de disponibilidad viene con Pro. La vista previa aparece al desbloquearlo.
Operaciones booleanas viene con Pro. La vista previa aparece al desbloquearlo.
Selector en cascada viene con Pro. La vista previa aparece al desbloquearlo.