Skip to main content
PimentCSS v1.0.1, what's new
Home

Autocomplete

Suggest list, keyboard navigation, and combobox patterns.

Overview

.autocomplete stacks a label, optional hint, a composite control (field + clear + search action), and an optional .autocomplete__panel with a .menu list. Open state uses .autocomplete--open. The clear control uses .autocomplete--has-value and only appears after a list selection (not while typing).

PartClassRole
Root.autocomplete328px max column, positions panel
Hint.autocomplete__hintHelper text under label
Control.autocomplete__controlBordered row: field + search button
Panel.autocomplete__panelAbsolute listbox with .menu
Selected.autocomplete--has-valueShows .autocomplete__clear

Prerequisites

Structure

Each option uses .menu__item-title (name) and .menu__item-desc (role). Tie the hint with aria-describedby. Use type="text" on the input to avoid the browser’s native search clear icon.

Default state

Panel hidden until focus or search. Add .autocomplete--open via the script; selected row uses .menu__item--selected.

Search by name or role

Behavior in your app

Copy and adapt docs-site/src/lib/autocomplete-behavior.ts after PimentCSS CSS is loaded. On this docs site, doc-client.ts calls bindAutocompleteDismiss() and wireAllAutocompletes() on load (same model as the date picker).

Interactive example

Focus the field or type a name or role. Pick a row with click or keyboard; the clear button appears only after a list selection. Use Escape or an outside click to close the panel.

Type a name or job title

Class reference

ClassDescription
.autocompleteRoot wrapper (328px max)
.autocomplete--openShows .autocomplete__panel
.autocomplete--has-valueReveals .autocomplete__clear after list pick
.autocomplete__hintHelper below label
.autocomplete__controlBordered input row + search
.autocomplete__fieldInput + clear (280px max)
.autocomplete__inputText input (combobox)
.autocomplete__clearClears committed selection
.autocomplete__searchPrimary search action
.menu__item-titlePrimary line in a suggestion
.menu__item-descSecondary line (role, team, etc.)
.autocomplete__panelListbox container

Customize (Sass)

  1. Autocomplete sizing

    Override width tokens before importing components.
    @use "pimentcss-design-system" with (
      $autocomplete-width: 20.5rem,
      $autocomplete-field-width: 17.5rem
    );
  2. Rebuild CSS

    Run after editing _autocomplete.scss or tokens.
    npm run build:css

Accessibility (RGAA / WCAG)

Combobox / listbox

  • Label, <label for="…"> on the input; hint via aria-describedby.
  • Combobox, role="combobox", aria-autocomplete="list", aria-controls, aria-expanded synced with open state.
  • Listbox, panel role="listbox" with an accessible name; options as role="option" buttons.
  • Selection, aria-selected="true" on the chosen option; reflect the name in the input.
  • Clear, one control only (type="text" + hidden .autocomplete__clear until a list value is committed).
  • Keyboard, Arrow Up/Down, Enter, Escape require app logic; CSS provides focus rings only.

Next steps