Search and choose one or more options from a list.
Package@g4rcez/componentsSectionForm Controls
Examples
Basic Autocomplete
A basic autocomplete with a list of programming languages. Selecting an option updates the controlled value.
Create a New Option
Use dynamicOption to select a suggested language or enter a new one without an option validation error. Press Enter, select the option, or leave the field to accept the typed value.
Left and Right Content
left and right put an icon, a hint or any element inside the field, before the text and next to the caret. The right content sits before the caret and the clear button, so those controls keep working. Decorative icons take aria-hidden, and the field keeps its own label.
Empty and Disabled States
Demonstrates autocomplete in empty and disabled states.
Autocomplete in Modal
Demonstrates how Autocomplete behaves when placed inside a Modal component.
Field Sizes
Use size=normal or size=small when you need autocomplete fields to fit different densities.
When to use Autocomplete
Use when
Use Autocomplete when a user selects one or more known options from a searchable list.
Avoid when
Avoid it for a short, stable list that is faster to scan as native radio buttons or a select.
Accessibility
Keep the field labeled, announce the expanded state, and make option movement and selection available from the keyboard.
data-value: on the hidden <input>. Holds the committed option value.
data-shadow="true": on the visible text input. Distinguishes it from the real field.
data-dynamic="true": on options injected by dynamicOption.
data-initialized: set internally. formReset uses it to track interaction state.
data-floating="true": on the floating panel element.
data-placement: bottom-start by default. top-start when space below the field is insufficient.
Design tokens
Geometry defaults use scoped calc fallbacks from --var-spacing-base and the independent --var-radius-base. Explicit semantic overrides stay unchanged. See Geometry tokens for default lookup, radius migration, theme emission, and exceptions. The exported defaultGeometryTokens map holds the full set. Current plain-CSS geometry examples:
Autocomplete tokens Override reference
Override
Library default
--var-autocomplete-list-max-block-size
calc(var(--var-spacing-base) * 24)
--var-autocomplete-panel-radius
calc(var(--var-radius-base) / 2)
--var-autocomplete-option-min-block-size
calc(var(--var-spacing-base) * 2.5)
--var-autocomplete-option-padding
calc(var(--var-spacing-base) * 0.625)
Popup maximum height and initial estimates scale with density.
Measured list content keeps its physical size.
Virtualizer pixel estimates are not fixed CSS dimensions.
Tailwind utility mappings and component tokens follow. When a utility targets a different surface, the Purpose column names the component token.
Autocomplete tokens Token reference
Token
CSS Variable
Purpose
h-input-height
--var-free-text-control-height
Input height
px-input-padding-x
--var-free-text-surface-padding-inline
Horizontal input padding
py-input-padding-y
--var-free-text-surface-padding-block
Vertical input padding
border-input-border
--var-color-input
Default field border color
placeholder-input-placeholder
--var-free-text-placeholder-foreground
Placeholder text color
placeholder-input-mask-error
--var-free-text-error-placeholder-foreground
Placeholder color in error state
text-foreground
--var-color-foreground
Input text color
text-danger
--var-color-danger
Text color in error state
text-primary
--var-color-primary
Focus/hover border and ring color
bg-floating-background
--var-dropdown-surface-background
Dropdown utility; the panel uses --var-autocomplete-panel-background
border-floating-border
--var-dropdown-surface-border
Dropdown border utility; the panel uses --var-autocomplete-panel-border
bg-floating-hover
--var-color-muted
Hover utility; options use --var-autocomplete-option-background-hover and --var-autocomplete-option-active-background
text-disabled
--var-color-disabled
Disabled text utility; the empty message uses --var-autocomplete-empty-foreground
border-tooltip-border
--var-tooltip-surface-border
Tooltip border utility; the empty-state separator uses --var-autocomplete-empty-border
z-floating
--var-layer-floating
Z-index for the floating panel
shadow-floating
--var-shadow-floating
Drop shadow for the floating panel
Accessibility
Keep the field labeled, announce the expanded state, and make option movement and selection available from the keyboard.
The dropdown has role="listbox" and is managed by @floating-ui/react.
The visible search input has role="combobox" and aria-autocomplete="list". It has expanded/listbox relations and aria-activedescendant for the active option.
Options have role="option", aria-selected for the committed value, and aria-disabled. Keyboard-active styling is separate from the selected value.
Options are not Tab stops.
Arrow Up/Down wraps through enabled, nonhidden options.
There is no result-count or empty-result live region.
Dynamic mode permits Tab/Shift+Tab departure and commits on blur.
Enter commits an active option, a sole enabled result, or eligible dynamic text.
Escape clears the pending query and closes the popup.
There are no custom Home/End/Page Up/Page Down handlers.
The caret button has an sr-only label from the translation system.
Dynamic-mode blur commits eligible text, does not restore focus, and uses nonmodal focus management. Fixed-option mode uses modal focus management.
Interaction and behavior
Adapted from: Select (Combo). This is a searchable combobox adaptation. It differs from native selects. The checks are source-informed design targets, not executed accessibility tests.
Enable dynamicOption only when the domain accepts text outside options. Tell users that leaving the field commits eligible text.
A persistent title names the field.
Focus, a click or tap on the input, or the caret opens suggestions. Typing filters them.
Enter or a click on an enabled option commits its value and shows its label. The popup closes and the input regains focus.
Hidden options are omitted. Arrow navigation skips disabled options. Pointer and Enter selection reject them.
Keep DOM focus on the combobox. Arrows change the active descendant. Selection state differs from the highlighted result.
In fixed-option mode, typed text alone does not commit a choice on blur. Validate the committed value. Displayed search text is not a submitted selection.
loading supplies no lock or announcement.
Consumer duties: provide loading and result feedback, and set disabled explicitly.
Consumer duties: verify focus exit, mounted active-descendant targets, and actual announcements with supported assistive technologies.
Consumer duties: persist created options, and validate the committed value and required (the hidden input has no native validation).
Consumer duties: ensure touch target size and focus visibility in the chosen theme.
Keep custom renderers noninteractive. Test coarse-pointer behavior. Native selection applies only without dynamic text or custom renderers.