# Autocomplete

Suggest text while someone types, without limiting what they can enter.

Use Autocomplete for a text field with helpful suggestions. Choosing one fills in the field, but any text is a valid value. Use [Combobox](/docs/angular/components/combobox) when the value should be a selected option instead.

```angular-ts title="demo.ts"
import { Component } from "@angular/core"
import {
  Autocomplete,
  AutocompleteContent,
  AutocompleteEmpty,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteLabel,
  AutocompleteList,
} from "@ui-sdk/angular/autocomplete"

@Component({
  imports: [
    Autocomplete,
    AutocompleteContent,
    AutocompleteEmpty,
    AutocompleteInput,
    AutocompleteItem,
    AutocompleteLabel,
    AutocompleteList,
  ],
  template: `
    <ng-container uiAutocomplete>
      <div data-slot="stack">
        <label uiAutocompleteLabel>Favorite fruit</label>
        <input uiAutocompleteInput placeholder="e.g. Mango" />
      </div>
      <div *uiAutocompleteContent>
        <div uiAutocompleteEmpty>No fruits found.</div>
        <div uiAutocompleteList>
          @for (fruit of fruits; track fruit) {
            <div uiAutocompleteItem [value]="fruit">
              {{ fruit }}
            </div>
          }
        </div>
      </div>
    </ng-container>
  `,
})
class Example {
  readonly fruits = [
    "Apple",
    "Apricot",
    "Avocado",
    "Banana",
    "Blackberry",
    "Blueberry",
    "Cherry",
    "Grape",
    "Lemon",
    "Mango",
    "Orange",
    "Peach",
    "Pear",
    "Pineapple",
    "Strawberry",
  ]
}

export { Example }
```

Type “man”, press Down Arrow, then Enter to fill in Mango. You can also leave text that is not in the list.

## Installation

```bash
npm install @ui-sdk/angular @ui-sdk/core
```

## Composition

Use the following composition to build Autocomplete:

```text
uiAutocomplete
├── uiAutocompleteLabel
├── uiAutocompleteInput
└── uiAutocompleteContent
    ├── uiAutocompleteEmpty
    └── uiAutocompleteList
        ├── uiAutocompleteItem
        └── uiAutocompleteItem
```

Name the input, then put suggestions in a list inside the popup. Each suggestion needs a unique value.

## Usage

Import the parts and put them together:

```ts
import { Component } from "@angular/core"
import {
  Autocomplete,
  AutocompleteContent,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteLabel,
  AutocompleteList,
} from "@ui-sdk/angular/autocomplete"

@Component({
  selector: "app-example",
  imports: [
    Autocomplete,
    AutocompleteContent,
    AutocompleteInput,
    AutocompleteItem,
    AutocompleteLabel,
    AutocompleteList,
  ],
  template: `
    <ng-container uiAutocomplete>
      <label uiAutocompleteLabel>Fruit</label>
      <input uiAutocompleteInput placeholder="Type a fruit…" />
      <div *uiAutocompleteContent>
        <div uiAutocompleteList>
          <div uiAutocompleteItem value="Apple">Apple</div>
          <div uiAutocompleteItem value="Banana">Banana</div>
        </div>
      </div>
    </ng-container>
  `,
})
class Example {}

export { Example }
```

## Autocomplete vs Combobox

Both filter a list as you type. They differ in what the value is.

- **Autocomplete**: the value is the text. Suggestions help fill it in, and anything typed is valid. Use it for a search box, an address or a free-form field.
- **[Combobox](/docs/angular/components/combobox)**: the value is an option from the list, or several with `multiple`. The text is only a query; closing without choosing restores the selected label, and a form submits the value, not the text. Use it for a country, an assignee or a set of labels.

## Build Your Own

`@ui-sdk/angular/autocomplete` comes with a ready-made Autocomplete. If you'd like to build your own, with your own names, start from the `autocomplete` primitive in `@ui-sdk/core`:

```ts title="fruit-search.ts"
import { Directive, inject, input } from "@angular/core"
import {
  autocomplete,
  type AutocompleteItemProps,
} from "@ui-sdk/core/autocomplete"
import { usePart, usePrimitive } from "@ui-sdk/angular/primitive"

@Directive({ selector: "[appFruitSearch]" })
class FruitSearch {
  readonly handle = usePrimitive(autocomplete, () => ({}))
}

@Directive({ selector: "[appFruitLabel]" })
class FruitLabel {
  readonly state = usePart(inject(FruitSearch).handle, "label").state
}

@Directive({ selector: "[appFruitInput]" })
class FruitInput {
  readonly state = usePart(inject(FruitSearch).handle, "input").state
}

@Directive({ selector: "[appFruitPopup]" })
class FruitPopup {
  readonly state = usePart(inject(FruitSearch).handle, "content").state
}

@Directive({ selector: "[appFruitList]" })
class FruitList {
  readonly state = usePart(inject(FruitSearch).handle, "list").state
}

@Directive({ selector: "[appFruitOption]" })
class FruitOption {
  readonly value = input.required<AutocompleteItemProps["value"]>()
  readonly state = usePart(inject(FruitSearch).handle, "item", () => ({
    value: this.value(),
  })).state
}

@Directive({ selector: "[appFruitEmpty]" })
class FruitEmpty {
  readonly state = usePart(inject(FruitSearch).handle, "empty").state
}

export {
  FruitEmpty,
  FruitInput,
  FruitLabel,
  FruitList,
  FruitOption,
  FruitPopup,
  FruitSearch,
}
```

```ts
import { Component } from "@angular/core"
import {
  FruitEmpty,
  FruitInput,
  FruitLabel,
  FruitList,
  FruitOption,
  FruitPopup,
  FruitSearch,
} from "./fruit-search"

@Component({
  selector: "app-fruit-search-example",
  imports: [
    FruitEmpty,
    FruitInput,
    FruitLabel,
    FruitList,
    FruitOption,
    FruitPopup,
    FruitSearch,
  ],
  template: `
    <ng-container appFruitSearch>
      <label appFruitLabel>Fruit</label>
      <input appFruitInput />
      <div appFruitPopup>
        <div appFruitEmpty>No fruits found.</div>
        <div appFruitList>
          <div appFruitOption value="Apple">Apple</div>
          <div appFruitOption value="Mango">Mango</div>
        </div>
      </div>
    </ng-container>
  `,
})
export class FruitSearchExample {}
```

Connect the other slots the same way, each with `usePart`. Each part keeps the behavior, state and data attributes of its ready-made counterpart: typing filters the options, arrow keys move the highlight and the popup opens in the top layer. See [Rendering Primitives](/docs/angular/rendering) and [Custom Parts](/docs/angular/custom-parts) for more.

## Disabled

A disabled field cannot be focused or changed and submits nothing. A read-only field stays focusable and submits its value, but does not open or accept changes. Disabled suggestions are skipped by keyboard navigation and cannot fill in the field.

```angular-ts title="disabled.ts"
import { Component } from "@angular/core"
import {
  Autocomplete,
  AutocompleteContent,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteLabel,
  AutocompleteList,
} from "@ui-sdk/angular/autocomplete"

@Component({
  imports: [
    Autocomplete,
    AutocompleteContent,
    AutocompleteInput,
    AutocompleteItem,
    AutocompleteLabel,
    AutocompleteList,
  ],
  template: `
    <div data-slot="stack">
      <ng-container uiAutocomplete disabled defaultValue="Banana">
        <div data-slot="stack">
          <label uiAutocompleteLabel>Disabled</label>
          <input uiAutocompleteInput />
        </div>
      </ng-container>
      <ng-container uiAutocomplete readOnly defaultValue="Cherry">
        <div data-slot="stack">
          <label uiAutocompleteLabel>Read-only</label>
          <input uiAutocompleteInput />
        </div>
      </ng-container>
      <ng-container uiAutocomplete>
        <div data-slot="stack">
          <label uiAutocompleteLabel>Some suggestions disabled</label>
          <input uiAutocompleteInput placeholder="Type “b”" />
        </div>
        <div *uiAutocompleteContent>
          <div uiAutocompleteList>
            @for (fruit of fruits; track fruit; let index = $index) {
              <div
                uiAutocompleteItem
                [value]="fruit"
                [disabled]="index % 3 === 0"
              >
                {{ fruit }}
              </div>
            }
          </div>
        </div>
      </ng-container>
    </div>
  `,
})
class Example {
  readonly fruits = [
    "Apple",
    "Apricot",
    "Avocado",
    "Banana",
    "Blackberry",
    "Blueberry",
    "Cherry",
    "Grape",
    "Lemon",
    "Mango",
    "Orange",
    "Peach",
    "Pear",
    "Pineapple",
    "Strawberry",
  ]
}

export { Example }
```

Try the Disabled and Read-only fields. In Disabled suggestion, type “b”: arrow keys skip Banana and a press cannot choose it.

## Clear and Trigger

`uiAutocompleteClear` empties the field and returns focus to it. `uiAutocompleteTrigger` lets someone open the suggestions without typing. Give the trigger a label that describes what it opens.

```angular-ts title="clear.ts"
import { Component } from "@angular/core"
import { LucideChevronDown, LucideX } from "@lucide/angular"
import {
  Autocomplete,
  AutocompleteClear,
  AutocompleteContent,
  AutocompleteEmpty,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteLabel,
  AutocompleteList,
  AutocompleteTrigger,
} from "@ui-sdk/angular/autocomplete"

@Component({
  imports: [
    Autocomplete,
    AutocompleteClear,
    AutocompleteContent,
    AutocompleteEmpty,
    AutocompleteInput,
    AutocompleteItem,
    AutocompleteLabel,
    AutocompleteList,
    AutocompleteTrigger,
    LucideChevronDown,
    LucideX,
  ],
  template: `
    <ng-container uiAutocomplete defaultValue="Mango">
      <div data-slot="stack">
        <label uiAutocompleteLabel>Fruit</label>
        <div data-slot="row">
          <input uiAutocompleteInput />
          <button *uiAutocompleteClear aria-label="Clear">
            <svg lucideX></svg>
          </button>
          <button uiAutocompleteTrigger aria-label="Show fruits">
            <svg lucideChevronDown></svg>
          </button>
        </div>
      </div>
      <div *uiAutocompleteContent>
        <div uiAutocompleteEmpty>No fruits found.</div>
        <div uiAutocompleteList>
          @for (fruit of fruits; track fruit) {
            <div uiAutocompleteItem [value]="fruit">
              {{ fruit }}
            </div>
          }
        </div>
      </div>
    </ng-container>
  `,
})
class Example {
  readonly fruits = [
    "Apple",
    "Apricot",
    "Avocado",
    "Banana",
    "Blackberry",
    "Blueberry",
    "Cherry",
    "Grape",
    "Lemon",
    "Mango",
    "Orange",
    "Peach",
    "Pear",
    "Pineapple",
    "Strawberry",
  ]
}

export { Example }
```

Clear Mango, then press Show fruits to open the suggestions. The clear button disappears while the field is empty.

## Open on Focus

Add `openOnFocus` to offer suggestions as soon as the input receives focus. This works well when there are useful choices before someone types.

```angular-ts title="open-on-focus.ts"
import { Component } from "@angular/core"
import {
  Autocomplete,
  AutocompleteContent,
  AutocompleteEmpty,
  AutocompleteGroup,
  AutocompleteGroupLabel,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteList,
} from "@ui-sdk/angular/autocomplete"

@Component({
  imports: [
    Autocomplete,
    AutocompleteContent,
    AutocompleteEmpty,
    AutocompleteGroup,
    AutocompleteGroupLabel,
    AutocompleteInput,
    AutocompleteItem,
    AutocompleteList,
  ],
  template: `
    <ng-container uiAutocomplete openOnFocus>
      <input uiAutocompleteInput aria-label="Search" placeholder="Search…" />
      <div *uiAutocompleteContent>
        <div uiAutocompleteEmpty>No results.</div>
        <div uiAutocompleteList>
          <div uiAutocompleteGroup>
            <div uiAutocompleteGroupLabel>Recent searches</div>
            @for (search of recent; track search) {
              <div uiAutocompleteItem [value]="search">
                {{ search }}
              </div>
            }
          </div>
        </div>
      </div>
    </ng-container>
  `,
})
class Example {
  readonly recent = [
    "react hooks",
    "tailwind grid",
    "web components",
    "vue v-model",
  ]
}

export { Example }
```

Focus Search docs to see recent searches before typing. Escape closes them; pressing the field opens them again.

## Auto Highlight

`autoHighlight` highlights the first match while typing, so Enter can choose it immediately. Set `loop` to `false` to stop arrow keys at either end of the list.

```angular-ts title="auto-highlight.ts"
import { Component } from "@angular/core"
import {
  Autocomplete,
  AutocompleteContent,
  AutocompleteEmpty,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteLabel,
  AutocompleteList,
} from "@ui-sdk/angular/autocomplete"

@Component({
  imports: [
    Autocomplete,
    AutocompleteContent,
    AutocompleteEmpty,
    AutocompleteInput,
    AutocompleteItem,
    AutocompleteLabel,
    AutocompleteList,
  ],
  template: `
    <ng-container uiAutocomplete autoHighlight [loop]="false">
      <div data-slot="stack">
        <label uiAutocompleteLabel>Fruit</label>
        <input uiAutocompleteInput placeholder="Type, then Enter" />
      </div>
      <div *uiAutocompleteContent>
        <div uiAutocompleteEmpty>No fruits found.</div>
        <div uiAutocompleteList>
          @for (fruit of fruits; track fruit) {
            <div uiAutocompleteItem [value]="fruit">
              {{ fruit }}
            </div>
          }
        </div>
      </div>
    </ng-container>
  `,
})
class Example {
  readonly fruits = [
    "Apple",
    "Apricot",
    "Avocado",
    "Banana",
    "Blackberry",
    "Blueberry",
    "Cherry",
    "Grape",
    "Lemon",
    "Mango",
    "Orange",
    "Peach",
    "Pear",
    "Pineapple",
    "Strawberry",
  ]
}

export { Example }
```

Type “pe” and press Enter to choose the first match. Arrow keys stop at the ends because this example disables looping.

## Inline Completion

`inlineComplete` fills in the rest of the first suggestion that starts with the typed text, with the added text selected. Arrow keys fill in the suggestion they highlight. End or Right Arrow accepts the completion; Backspace or Escape takes it back out.

```angular-ts title="inline.ts"
import { Component } from "@angular/core"
import {
  Autocomplete,
  AutocompleteContent,
  AutocompleteEmpty,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteLabel,
  AutocompleteList,
} from "@ui-sdk/angular/autocomplete"

@Component({
  imports: [
    Autocomplete,
    AutocompleteContent,
    AutocompleteEmpty,
    AutocompleteInput,
    AutocompleteItem,
    AutocompleteLabel,
    AutocompleteList,
  ],
  template: `
    <ng-container uiAutocomplete inlineComplete>
      <div data-slot="stack">
        <label uiAutocompleteLabel>Fruit</label>
        <input uiAutocompleteInput placeholder="Type “bl”" />
      </div>
      <div *uiAutocompleteContent>
        <div uiAutocompleteEmpty>No fruits found.</div>
        <div uiAutocompleteList>
          @for (fruit of fruits; track fruit) {
            <div uiAutocompleteItem [value]="fruit">
              {{ fruit }}
            </div>
          }
        </div>
      </div>
    </ng-container>
  `,
})
class Example {
  readonly fruits = [
    "Apple",
    "Apricot",
    "Avocado",
    "Banana",
    "Blackberry",
    "Blueberry",
    "Cherry",
    "Grape",
    "Lemon",
    "Mango",
    "Orange",
    "Peach",
    "Pear",
    "Pineapple",
    "Strawberry",
  ]
}

export { Example }
```

Type “bl” to complete blackberry inline. Backspace removes the completion; Down Arrow fills in Blueberry. Press End to accept the text.

## Highlight Matches

`uiAutocompleteItemText` marks the matching text, ignoring case and accents using the current locale. Its state exposes the matching segments when you want to render them yourself, as this example does in bold.

```angular-ts title="highlight.ts"
import { Component } from "@angular/core"
import {
  Autocomplete,
  AutocompleteContent,
  AutocompleteEmpty,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteItemText,
  AutocompleteLabel,
  AutocompleteList,
} from "@ui-sdk/angular/autocomplete"

@Component({
  imports: [
    Autocomplete,
    AutocompleteContent,
    AutocompleteEmpty,
    AutocompleteInput,
    AutocompleteItem,
    AutocompleteItemText,
    AutocompleteLabel,
    AutocompleteList,
  ],
  template: `
    <ng-container uiAutocomplete>
      <div data-slot="stack">
        <label uiAutocompleteLabel>Favorite fruit</label>
        <input uiAutocompleteInput placeholder="e.g. berry" />
      </div>
      <div *uiAutocompleteContent>
        <div uiAutocompleteEmpty>No fruits found.</div>
        <div uiAutocompleteList>
          @for (fruit of fruits; track fruit) {
            <div uiAutocompleteItem [value]="fruit">
              <span
                uiAutocompleteItemText
                #autocompleteItemText="uiAutocompleteItemText"
              >
                @for (
                  segment of autocompleteItemText.state().segments;
                  track index;
                  let index = $index
                ) {
                  @if (segment.match) {
                    <strong>{{ segment.text }}</strong>
                  } @else {
                    <span>{{ segment.text }}</span>
                  }
                }
              </span>
            </div>
          }
        </div>
      </div>
    </ng-container>
  `,
})
class Example {
  readonly fruits = [
    "Apple",
    "Apricot",
    "Avocado",
    "Banana",
    "Blackberry",
    "Blueberry",
    "Cherry",
    "Grape",
    "Lemon",
    "Mango",
    "Orange",
    "Peach",
    "Pear",
    "Pineapple",
    "Strawberry",
  ]
}

export { Example }
```

Type “berry”. The matching letters are bold while each suggestion keeps its original spelling.

## Filter and Keywords

The default filter matches text anywhere in a suggestion. Use `"startsWith"` or `"fuzzy"` for a different match, a function for your own filter, or `false` for results already filtered by a server. `keywords` adds searchable text without changing what goes in the field.

```angular-ts title="filter.ts"
import { Component } from "@angular/core"
import {
  Autocomplete,
  AutocompleteContent,
  AutocompleteEmpty,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteLabel,
  AutocompleteList,
} from "@ui-sdk/angular/autocomplete"

@Component({
  imports: [
    Autocomplete,
    AutocompleteContent,
    AutocompleteEmpty,
    AutocompleteInput,
    AutocompleteItem,
    AutocompleteLabel,
    AutocompleteList,
  ],
  template: `
    <ng-container uiAutocomplete filter="startsWith">
      <div data-slot="stack">
        <label uiAutocompleteLabel>Tag</label>
        <input uiAutocompleteInput placeholder="Try “bug”" />
      </div>
      <div *uiAutocompleteContent>
        <div uiAutocompleteEmpty>No tags found.</div>
        <div uiAutocompleteList>
          @for (tag of tags; track tag.value) {
            <div
              uiAutocompleteItem
              [value]="tag.value"
              [label]="tag.label"
              [keywords]="tag.keywords"
            >
              {{ tag.label }}
              <span data-slot="hint">{{ tag.keywords[0] }}</span>
            </div>
          }
        </div>
      </div>
    </ng-container>
  `,
})
class Example {
  readonly tags = [
    {
      value: "feature",
      label: "feature",
      keywords: ["enhancement", "request"],
    },
    { value: "fix", label: "fix", keywords: ["bug", "patch"] },
    { value: "docs", label: "docs", keywords: ["documentation", "readme"] },
    { value: "performance", label: "performance", keywords: ["speed", "slow"] },
    { value: "security", label: "security", keywords: ["vulnerability"] },
    { value: "refactor", label: "refactor", keywords: ["cleanup"] },
  ]
}

export { Example }
```

Type “bug” to find fix through its keywords. Type “re” to find labels or keywords that start with those letters.

## Groups

Use `uiAutocompleteGroup` and `uiAutocompleteGroupLabel` to name related suggestions. Filtering hides empty groups and separators.

```angular-ts title="groups.ts"
import { Component } from "@angular/core"
import {
  Autocomplete,
  AutocompleteContent,
  AutocompleteEmpty,
  AutocompleteGroup,
  AutocompleteGroupLabel,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteLabel,
  AutocompleteList,
  AutocompleteSeparator,
} from "@ui-sdk/angular/autocomplete"

@Component({
  imports: [
    Autocomplete,
    AutocompleteContent,
    AutocompleteEmpty,
    AutocompleteGroup,
    AutocompleteGroupLabel,
    AutocompleteInput,
    AutocompleteItem,
    AutocompleteLabel,
    AutocompleteList,
    AutocompleteSeparator,
  ],
  template: `
    <ng-container uiAutocomplete>
      <div data-slot="stack">
        <label uiAutocompleteLabel>Fruit</label>
        <input uiAutocompleteInput placeholder="e.g. Pear" />
      </div>
      <div *uiAutocompleteContent>
        <div uiAutocompleteEmpty>No fruits found.</div>
        <div uiAutocompleteList>
          @for (group of fruitGroups; track group.label; let index = $index) {
            @if (index > 0) {
              <div uiAutocompleteSeparator></div>
            }
            <div uiAutocompleteGroup>
              <div uiAutocompleteGroupLabel>{{ group.label }}</div>
              @for (fruit of group.items; track fruit) {
                <div uiAutocompleteItem [value]="fruit">
                  {{ fruit }}
                </div>
              }
            </div>
          }
        </div>
      </div>
    </ng-container>
  `,
})
class Example {
  readonly fruitGroups = [
    {
      label: "Tree fruits",
      items: ["Apple", "Apricot", "Cherry", "Lemon", "Peach", "Pear"],
    },
    {
      label: "Berries",
      items: ["Blackberry", "Blueberry", "Grape", "Strawberry"],
    },
    { label: "Tropical", items: ["Avocado", "Banana", "Mango", "Pineapple"] },
  ]
}

export { Example }
```

Type “an”. Banana and Mango remain in Tropical; groups with no matches disappear.

## Icons

`uiAutocompleteItemIcon` keeps decorative icons out of accessible names, filtering, and the text put in the field. Add `mirror` for directional icons. An icon-only suggestion still needs an `aria-label`.

```angular-ts title="icons.ts"
import { Component } from "@angular/core"
import {
  LucideArchive,
  LucideClock,
  LucideDynamicIcon,
  LucideFile,
  LucidePencil,
  LucideReply,
  LucideStar,
} from "@lucide/angular"
import {
  Autocomplete,
  AutocompleteContent,
  AutocompleteEmpty,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteItemIcon,
  AutocompleteList,
} from "@ui-sdk/angular/autocomplete"

@Component({
  imports: [
    Autocomplete,
    AutocompleteContent,
    AutocompleteEmpty,
    AutocompleteInput,
    AutocompleteItem,
    AutocompleteItemIcon,
    AutocompleteList,
    LucideDynamicIcon,
  ],
  template: `
    <ng-container uiAutocomplete>
      <input
        uiAutocompleteInput
        type="search"
        aria-label="Search mail"
        placeholder="Search mail…"
      />
      <div *uiAutocompleteContent>
        <div uiAutocompleteEmpty>No searches found.</div>
        <div uiAutocompleteList>
          @for (search of mailSearches; track search.value) {
            <div uiAutocompleteItem [value]="search.value">
              <span uiAutocompleteItemIcon [mirror]="search.mirror">
                <svg [lucideIcon]="search.icon"></svg>
              </span>
              {{ search.value }}
            </div>
          }
        </div>
      </div>
    </ng-container>
  `,
})
class Example {
  readonly mailSearches = [
    { value: "Starred", icon: LucideStar },
    { value: "Drafts", icon: LucidePencil },
    { value: "Replies", icon: LucideReply, mirror: true },
    { value: "Attachments", icon: LucideFile },
    { value: "Archived", icon: LucideArchive },
    { value: "Scheduled", icon: LucideClock },
  ]
}

export { Example }
```

Type “rep” and choose Replies. The icon stays out of the text put in the field.

## Items as Data

Map an array into parts when you want to write the markup yourself. This example maps fruit groups and adds a separator between them.

```angular-ts title="data.ts"
import { Component } from "@angular/core"
import {
  Autocomplete,
  AutocompleteContent,
  AutocompleteEmpty,
  AutocompleteGroup,
  AutocompleteGroupLabel,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteLabel,
  AutocompleteList,
  AutocompleteSeparator,
} from "@ui-sdk/angular/autocomplete"

@Component({
  imports: [
    Autocomplete,
    AutocompleteContent,
    AutocompleteEmpty,
    AutocompleteGroup,
    AutocompleteGroupLabel,
    AutocompleteInput,
    AutocompleteItem,
    AutocompleteLabel,
    AutocompleteList,
    AutocompleteSeparator,
  ],
  template: `
    <ng-container uiAutocomplete>
      <div data-slot="stack">
        <label uiAutocompleteLabel>Fruit</label>
        <input uiAutocompleteInput placeholder="e.g. Peach" />
      </div>
      <div *uiAutocompleteContent>
        <div uiAutocompleteEmpty>No fruits found.</div>
        <div uiAutocompleteList>
          @for (group of fruitGroups; track group.label; let index = $index) {
            @if (index > 0) {
              <div uiAutocompleteSeparator></div>
            }
            <div uiAutocompleteGroup>
              <div uiAutocompleteGroupLabel>{{ group.label }}</div>
              @for (fruit of group.fruits; track fruit) {
                <div uiAutocompleteItem [value]="fruit">{{ fruit }}</div>
              }
            </div>
          }
        </div>
      </div>
    </ng-container>
  `,
})
class Example {
  readonly fruitGroups = [
    {
      label: "Tree fruits",
      fruits: ["Apple", "Apricot", "Cherry", "Lemon", "Peach", "Pear"],
    },
    {
      label: "Berries",
      fruits: ["Blackberry", "Blueberry", "Grape", "Strawberry"],
    },
    { label: "Tropical", fruits: ["Avocado", "Banana", "Mango", "Pineapple"] },
  ]
}

export { Example }
```

Open the list to see three fruit groups. Type “an” to narrow them to Banana and Mango.

Pass `items` when the autocomplete needs the whole collection, such as server results or recent searches. `uiAutocompleteItems` inside the list renders bare parts for you. To style changing results, render from the list’s `state().items`. [Lists and Menus](/docs/angular/lists-and-menus) covers the `ListData` format.

Suggestions can change while the list is open. The highlight stays with its suggestion, and the typed text stays unchanged. Removing the highlighted suggestion clears the highlight.

## Controlled

The value is always a string. Control it with `value` and `(beforeValueChange)`, or start uncontrolled with `defaultValue`. Suggestions have a separate `open` state and `(beforeOpenChange)`. Callbacks receive the proposed value first, then change details. Call `$event.cancel()` to reject a text or open change. When a suggestion is chosen, `details.item` holds its `value` and `label`, so suggestions that share a label can still be told apart. [State and Events](/docs/angular/state-and-events) covers controlled state and cancellation.

```angular-ts title="controlled.ts"
import { Component, signal } from "@angular/core"
import { useLog } from "./log"
import {
  Autocomplete,
  AutocompleteContent,
  AutocompleteEmpty,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteLabel,
  AutocompleteList,
} from "@ui-sdk/angular/autocomplete"

@Component({
  imports: [
    Autocomplete,
    AutocompleteContent,
    AutocompleteEmpty,
    AutocompleteInput,
    AutocompleteItem,
    AutocompleteLabel,
    AutocompleteList,
  ],
  template: `
    <div data-slot="stack">
      <ng-container
        uiAutocomplete
        [(value)]="value"
        [(open)]="open"
        debug
        (beforeValueChange)="changeValue($event.value, $event)"
        (beforeOpenChange)="
          log(($event.value ? 'opened' : 'closed') + ': ' + $event.reason)
        "
        (openChangeComplete)="
          log(($event ? 'opened' : 'closed') + ' and settled')
        "
        (highlight)="$event.value && log('highlighted ' + $event.value)"
      >
        <label uiAutocompleteLabel>Fruit (12 characters at most)</label>
        <input uiAutocompleteInput />
        <div *uiAutocompleteContent>
          <div uiAutocompleteEmpty>No fruits found.</div>
          <div uiAutocompleteList>
            @for (fruit of fruits; track fruit) {
              <div uiAutocompleteItem [value]="fruit">
                {{ fruit }}
              </div>
            }
          </div>
        </div>
      </ng-container>
    </div>
  `,
})
class Example {
  readonly fruits = [
    "Apple",
    "Apricot",
    "Avocado",
    "Banana",
    "Blackberry",
    "Blueberry",
    "Cherry",
    "Grape",
    "Lemon",
    "Mango",
    "Orange",
    "Peach",
    "Pear",
    "Pineapple",
    "Strawberry",
  ]

  readonly log = useLog()

  readonly value = signal("")

  readonly open = signal(false)

  changeValue(next: string, details: { reason: string; cancel: () => void }) {
    if (next.length > 12) {
      return details.cancel()
    }
    this.log(`text: ${details.reason}`)
  }
}

export { Example }
```

Type more than 12 characters and the extra text is refused. The console shows each change and its reason.

## Controller

Create a `createAutocompleteController()` for one instance and pass it as `controller`. It can `setValue()`, `clear()`, `focus()`, `setOpen()`, or read `getValue()` and `isOpen()`. `open()` returns a promise that resolves when the popup closes, including abort and unmount; `close()` closes it. See [Controllers](/docs/angular/controllers) for lifecycle and change options.

```angular-ts title="controller.ts"
import { Component } from "@angular/core"
import {
  Autocomplete,
  AutocompleteContent,
  AutocompleteEmpty,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteLabel,
  AutocompleteList,
  createAutocompleteController,
} from "@ui-sdk/angular/autocomplete"

@Component({
  imports: [
    Autocomplete,
    AutocompleteContent,
    AutocompleteEmpty,
    AutocompleteInput,
    AutocompleteItem,
    AutocompleteLabel,
    AutocompleteList,
  ],
  template: `
    <div data-slot="stack">
      <div data-slot="controls">
        <button type="button" data-size="sm" (click)="fruit.open()">
          Open
        </button>
        <button type="button" data-size="sm" (click)="fruit.setValue('Pea')">
          Type “Pea”
        </button>
        <button type="button" data-size="sm" (click)="fruit.clear()">
          Clear
        </button>
        <button type="button" data-size="sm" (click)="fruit.focus()">
          Focus
        </button>
      </div>
      <ng-container uiAutocomplete [controller]="fruit">
        <label uiAutocompleteLabel>Fruit</label>
        <input uiAutocompleteInput />
        <div *uiAutocompleteContent>
          <div uiAutocompleteEmpty>No fruits found.</div>
          <div uiAutocompleteList>
            @for (item of fruits; track item) {
              <div uiAutocompleteItem [value]="item">
                {{ item }}
              </div>
            }
          </div>
        </div>
      </ng-container>
    </div>
  `,
})
class Example {
  readonly fruits = [
    "Apple",
    "Apricot",
    "Avocado",
    "Banana",
    "Blackberry",
    "Blueberry",
    "Cherry",
    "Grape",
    "Lemon",
    "Mango",
    "Orange",
    "Peach",
    "Pear",
    "Pineapple",
    "Strawberry",
  ]

  readonly fruit = createAutocompleteController()
}

export { Example }
```

Use the buttons to open the suggestions, type Pea, clear the field or focus it from outside.

## Positioning

Use `side`, `align`, offsets, or a custom `anchor` to position the suggestions. `container` chooses where they render, and `keepMounted` keeps closed content in the DOM. [Popups](/docs/angular/popups) covers positioning, portals, animation, and modal behavior.

```angular-ts title="positioning.ts"
import { Component } from "@angular/core"
import {
  Autocomplete,
  AutocompleteContent,
  AutocompleteEmpty,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteLabel,
  AutocompleteList,
} from "@ui-sdk/angular/autocomplete"

@Component({
  imports: [
    Autocomplete,
    AutocompleteContent,
    AutocompleteEmpty,
    AutocompleteInput,
    AutocompleteItem,
    AutocompleteLabel,
    AutocompleteList,
  ],
  template: `
    <div #box data-slot="card">
      <ng-container uiAutocomplete modal="pointer" [container]="box">
        <div data-slot="stack">
          <label uiAutocompleteLabel>Fruit</label>
          <input uiAutocompleteInput />
        </div>
        <div
          *uiAutocompleteContent="{
            side: 'top',
            align: 'end',
            sideOffset: 10,
            alignOffset: -4,
            collisionPadding: 8,
            anchor: box,
            keepMounted: true,
          }"
        >
          <div uiAutocompleteEmpty>No fruits found.</div>
          <div uiAutocompleteList>
            @for (fruit of fruits; track fruit) {
              <div uiAutocompleteItem [value]="fruit">
                {{ fruit }}
              </div>
            }
          </div>
        </div>
      </ng-container>
    </div>
  `,
})
class Example {
  readonly fruits = [
    "Apple",
    "Apricot",
    "Avocado",
    "Banana",
    "Blackberry",
    "Blueberry",
  ]
}

export { Example }
```

Open the suggestions. They appear above the card, aligned to its end.

## Animation

The content has `data-starting-style` while it opens and `data-ending-style` while it closes. Transition from those states, and the popup stays mounted until the exit finishes:

```css
[data-slot="autocomplete-content"] {
  transition:
    opacity 0.15s,
    translate 0.2s cubic-bezier(0.22, 1, 0.36, 1);

  &:is([data-starting-style], [data-ending-style]) {
    opacity: 0;
    translate: 0 -6px;
  }
}
```

```angular-ts title="animation.ts"
import { Component } from "@angular/core"
import {
  Autocomplete,
  AutocompleteContent,
  AutocompleteEmpty,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteLabel,
  AutocompleteList,
} from "@ui-sdk/angular/autocomplete"

@Component({
  imports: [
    Autocomplete,
    AutocompleteContent,
    AutocompleteEmpty,
    AutocompleteInput,
    AutocompleteItem,
    AutocompleteLabel,
    AutocompleteList,
  ],
  template: `
    <ng-container uiAutocomplete>
      <div data-slot="stack">
        <label uiAutocompleteLabel>Favorite fruit</label>
        <input uiAutocompleteInput placeholder="e.g. Mango" />
      </div>
      <div *uiAutocompleteContent>
        <div uiAutocompleteEmpty>No fruits found.</div>
        <div uiAutocompleteList>
          @for (fruit of fruits; track fruit) {
            <div uiAutocompleteItem [value]="fruit">
              {{ fruit }}
            </div>
          }
        </div>
      </div>
    </ng-container>
  `,
})
class Example {
  readonly fruits = [
    "Apple",
    "Apricot",
    "Avocado",
    "Banana",
    "Blackberry",
    "Blueberry",
    "Cherry",
    "Grape",
    "Lemon",
    "Mango",
    "Orange",
    "Peach",
    "Pear",
    "Pineapple",
    "Strawberry",
  ]
}

export { Example }
```

Type to open the suggestions. They slide and fade in, and fade out before they unmount.

## Presentation

`presentation="sheet"` opens suggestions in a sheet. `"auto"` chooses a sheet on small touch screens and a popover elsewhere, each time the list opens. The server starts with the popover.

The same input moves into the sheet’s header. Opening by touch leaves the keyboard closed; tapping the input opens it and expands the sheet. Choosing a suggestion or swiping down closes it. Keyboard and mouse opening preserve input focus.

A sheet is modal unless `modal` is `false`. Give it a height, keep suggestions inside `uiAutocompleteList`, and leave the content’s `translate` alone so dragging can move it. Use `data-presentation` to style both presentations and `--sheet-backdrop` to set the dimmed background.

```angular-ts title="presentation.ts"
import { Component } from "@angular/core"
import {
  Autocomplete,
  AutocompleteContent,
  AutocompleteEmpty,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteLabel,
  AutocompleteList,
} from "@ui-sdk/angular/autocomplete"

@Component({
  imports: [
    Autocomplete,
    AutocompleteContent,
    AutocompleteEmpty,
    AutocompleteInput,
    AutocompleteItem,
    AutocompleteLabel,
    AutocompleteList,
  ],
  template: `
    <ng-container uiAutocomplete presentation="sheet">
      <div data-slot="stack">
        <label uiAutocompleteLabel>Favorite fruit</label>
        <input uiAutocompleteInput placeholder="e.g. Mango" />
      </div>
      <div *uiAutocompleteContent>
        <div uiAutocompleteEmpty>No fruits found.</div>
        <div uiAutocompleteList>
          @for (fruit of fruits; track fruit) {
            <div uiAutocompleteItem [value]="fruit">
              {{ fruit }}
            </div>
          }
        </div>
      </div>
    </ng-container>
  `,
})
class Example {
  readonly fruits = [
    "Apple",
    "Apricot",
    "Avocado",
    "Banana",
    "Blackberry",
    "Blueberry",
    "Cherry",
    "Grape",
    "Lemon",
    "Mango",
    "Orange",
    "Peach",
    "Pear",
    "Pineapple",
    "Strawberry",
  ]
}

export { Example }
```

Open the field to see a sheet. On touch, tap the field in its header to show the keyboard, or swipe down to close it.

## Forms

The native input is the form control: `name` gives its submitted key, `required` rejects empty text, and reset restores `defaultValue`. Text does not have to match a suggestion. Use `form` to associate the field with a form elsewhere in the page.

```angular-ts title="form.ts"
import { Component } from "@angular/core"
import { useLog } from "./log"
import {
  Autocomplete,
  AutocompleteContent,
  AutocompleteEmpty,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteList,
} from "@ui-sdk/angular/autocomplete"
import {
  Field,
  FieldDescription,
  FieldError,
  FieldLabel,
} from "@ui-sdk/angular/field"

@Component({
  imports: [
    Autocomplete,
    AutocompleteContent,
    AutocompleteEmpty,
    AutocompleteInput,
    AutocompleteItem,
    AutocompleteList,
    Field,
    FieldDescription,
    FieldError,
    FieldLabel,
  ],
  template: `
    <form id="order" data-slot="stack" (submit)="submit($event)">
      <div uiField>
        <label uiFieldLabel>Fruit</label>
        <ng-container
          uiAutocomplete
          name="fruit"
          form="order"
          required
          defaultValue="Apple"
        >
          <input uiAutocompleteInput />
          <div *uiAutocompleteContent>
            <div uiAutocompleteEmpty>No fruits found.</div>
            <div uiAutocompleteList>
              @for (fruit of fruits; track fruit) {
                <div uiAutocompleteItem [value]="fruit">
                  {{ fruit }}
                </div>
              }
            </div>
          </div>
        </ng-container>
        <p uiFieldDescription>Any fruit, listed or not.</p>
        <div><div *uiFieldError></div></div>
      </div>
      <div data-slot="row">
        <button type="submit" data-variant="solid">Submit</button>
        <button type="reset">Reset</button>
      </div>
    </form>
  `,
})
class Example {
  readonly fruits = [
    "Apple",
    "Apricot",
    "Avocado",
    "Banana",
    "Blackberry",
    "Blueberry",
    "Cherry",
    "Grape",
    "Lemon",
    "Mango",
    "Orange",
    "Peach",
    "Pear",
    "Pineapple",
    "Strawberry",
  ]

  readonly log = useLog()

  submit(event: SubmitEvent) {
    event.preventDefault()
    const data = [...new FormData(event.currentTarget as HTMLFormElement)].map(
      ([name, value]) => `${name}=${value}`
    )
    this.log(`Submitted ${data.join("&")}`)
  }
}

export { Example }
```

Submit Apple, then choose Mango. Choosing it fills the field without submitting. Reset restores Apple.

## Search

Enter with no suggestion highlighted emits `(submit)` with the text, then lets the surrounding form submit. Call `$event.event.preventDefault()` if your handler already performs the search.

Choosing a suggestion normally only fills in the field. Add `submitOnSelect` to search as soon as someone chooses one.

```angular-ts title="search.ts"
import { Component } from "@angular/core"
import { useLog } from "./log"
import {
  Autocomplete,
  AutocompleteContent,
  AutocompleteEmpty,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteList,
} from "@ui-sdk/angular/autocomplete"

@Component({
  imports: [
    Autocomplete,
    AutocompleteContent,
    AutocompleteEmpty,
    AutocompleteInput,
    AutocompleteItem,
    AutocompleteList,
  ],
  template: `
    <form role="search" data-slot="stack" (submit)="$event.preventDefault()">
      <ng-container
        uiAutocomplete
        submitOnSelect
        name="q"
        (submit)="log('Searched “' + $event.value + '”')"
      >
        <input
          uiAutocompleteInput
          type="search"
          aria-label="Search"
          placeholder="Search…"
        />
        <div *uiAutocompleteContent>
          <div uiAutocompleteEmpty>No results.</div>
          <div uiAutocompleteList>
            @for (search of recent; track search) {
              <div uiAutocompleteItem [value]="search">
                {{ search }}
              </div>
            }
          </div>
        </div>
      </ng-container>
    </form>
  `,
})
class Example {
  readonly recent = [
    "react hooks",
    "tailwind grid",
    "web components",
    "vue v-model",
  ]

  readonly log = useLog()
}

export { Example }
```

Type “kotlin” and press Enter to search. Choose a suggestion to search for that text instead.

## Recent Searches

Pair `emptyItems` with `items` to show one collection while the field is empty and search the full collection once someone types. Add `openOnFocus` to show the recent searches on focus.

```angular-ts title="recent.ts"
import { Component } from "@angular/core"
import {
  Autocomplete,
  AutocompleteContent,
  AutocompleteEmpty,
  AutocompleteGroup,
  AutocompleteGroupLabel,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteItemText,
  AutocompleteList,
} from "@ui-sdk/angular/autocomplete"
import { type ListAnnouncement } from "@ui-sdk/core/autocomplete"

const recent = ["react hooks", "tailwind grid", "web components", "vue v-model"]

const recentSearches = [
  { type: "group" as const, label: "Recent searches", items: recent },
]

@Component({
  imports: [
    Autocomplete,
    AutocompleteContent,
    AutocompleteEmpty,
    AutocompleteGroup,
    AutocompleteGroupLabel,
    AutocompleteInput,
    AutocompleteItem,
    AutocompleteItemText,
    AutocompleteList,
  ],
  template: `
    <ng-container
      uiAutocomplete
      [items]="topics"
      [emptyItems]="recentSearches"
      openOnFocus
      [announcement]="announcement"
    >
      <input
        uiAutocompleteInput
        type="search"
        aria-label="Search docs"
        placeholder="Search docs…"
      />
      <div *uiAutocompleteContent>
        <div uiAutocompleteEmpty>No topics found.</div>
        <div uiAutocompleteList #autocompleteList="uiAutocompleteList">
          @for (
            entry of itemsOf(autocompleteList.state().items);
            track typeof entry === "string" ? entry : entry.label
          ) {
            @if (typeof entry === "string") {
              <div uiAutocompleteItem [value]="entry">
                <span uiAutocompleteItemText></span>
              </div>
            } @else {
              <div uiAutocompleteGroup>
                <div uiAutocompleteGroupLabel>{{ entry.label }}</div>
                @for (topic of entry.items; track topic) {
                  <div uiAutocompleteItem [value]="topic">
                    <span uiAutocompleteItemText></span>
                  </div>
                }
              </div>
            }
          }
        </div>
      </div>
    </ng-container>
  `,
})
class Example {
  readonly recent = recent

  readonly topics = [
    ...this.recent,
    "react server components",
    "tailwind colors",
    "vue router",
  ]

  readonly recentSearches = recentSearches

  announcement(change: ListAnnouncement) {
    return change.type === "results"
      ? `${change.count} ${change.count === 1 ? "topic" : "topics"}`
      : null
  }

  itemsOf(items: unknown) {
    return items as (string | (typeof recentSearches)[number])[]
  }
}

export { Example }
```

Focus the empty field to see Recent searches. Type “react” to search all topics, then clear the text to return to recent searches.

## Async Suggestions

Use [async options](/docs/angular/utilities/async-options) to wait for typing to pause and discard stale results. Pass its `items` and `status`, set `filter` to `false`, and send text changes to its `setQuery()` method.

`uiAutocompleteStatus` and `uiAutocompleteEmpty` provide loading, error, and empty messages. Without a status part, `announcement` controls what screen readers hear when typing pauses. `(loadMore)` can request another page when scrolling or highlighting reaches the last suggestion.

```angular-ts title="async.ts"
import { Component } from "@angular/core"
import { useAsyncOptions } from "@ui-sdk/angular/async-options"
import {
  Autocomplete,
  AutocompleteContent,
  AutocompleteEmpty,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteLabel,
  AutocompleteList,
  AutocompleteStatus,
} from "@ui-sdk/angular/autocomplete"

@Component({
  imports: [
    Autocomplete,
    AutocompleteContent,
    AutocompleteEmpty,
    AutocompleteInput,
    AutocompleteItem,
    AutocompleteLabel,
    AutocompleteList,
    AutocompleteStatus,
  ],
  template: `
    <ng-container
      uiAutocomplete
      [items]="results.state().items"
      [filter]="false"
      [status]="results.state().status"
      (beforeValueChange)="results.setQuery($event.value)"
      (loadMore)="results.loadMore()"
    >
      <div data-slot="stack">
        <label uiAutocompleteLabel>City</label>
        <input uiAutocompleteInput placeholder="e.g. Paris" />
      </div>
      <div *uiAutocompleteContent>
        <div uiAutocompleteStatus #autocompleteStatus="uiAutocompleteStatus">
          {{
            autocompleteStatus.state().loading
              ? "Searching…"
              : autocompleteStatus.state().count
                ? autocompleteStatus.state().count +
                  " " +
                  (autocompleteStatus.state().count === 1 ? "city" : "cities")
                : ""
          }}
        </div>
        <div uiAutocompleteEmpty #autocompleteEmpty="uiAutocompleteEmpty">
          @if (
            autocompleteEmpty.state().empty &&
            !autocompleteEmpty.state().loading
          ) {
            No cities start with “{{ autocompleteEmpty.state().query }}”.
          }
        </div>
        <div uiAutocompleteList #autocompleteList="uiAutocompleteList">
          @for (city of itemsOf(autocompleteList.state().items); track city) {
            <div uiAutocompleteItem [value]="city">
              {{ city }}
            </div>
          }
        </div>
      </div>
    </ng-container>
  `,
})
class Example {
  readonly searchCities = (
    query: string,
    { signal }: { signal: AbortSignal }
  ) => {
    const cities = [
      "Amsterdam",
      "Athens",
      "Barcelona",
      "Berlin",
      "Boston",
      "Brussels",
      "Buenos Aires",
      "Cairo",
      "Chicago",
      "Copenhagen",
      "Dublin",
      "Lisbon",
      "London",
      "Los Angeles",
      "Madrid",
      "Paris",
      "Prague",
      "Rome",
      "Seoul",
      "Tokyo",
    ]
    return new Promise<string[]>((resolve, reject) => {
      const timer = setTimeout(() => {
        const needle = query.trim().toLowerCase()
        resolve(cities.filter((city) => city.toLowerCase().startsWith(needle)))
      }, 300)
      signal.addEventListener("abort", () => {
        clearTimeout(timer)
        reject(new DOMException("Aborted", "AbortError"))
      })
    })
  }

  readonly results = useAsyncOptions(this.searchCities, { debounce: 200 })

  itemsOf(items: unknown) {
    return items as string[]
  }
}

export { Example }
```

Type “b” and wait for the city suggestions. Keep typing to replace the search; the status describes the latest results.

## Custom Rendering

Put `uiAutocompleteItem` on the element you want. Here each suggestion is a link, so the autocomplete works as a jump-to menu: Enter or a click follows the highlighted link, and the text after the title is a hint that doesn't affect filtering. [Parts and Composition](/docs/angular/parts-and-composition) covers the shared pattern.

```angular-ts title="custom-rendering.ts"
import { Component } from "@angular/core"
import {
  Autocomplete,
  AutocompleteContent,
  AutocompleteEmpty,
  AutocompleteInput,
  AutocompleteItem,
  AutocompleteLabel,
  AutocompleteList,
} from "@ui-sdk/angular/autocomplete"

@Component({
  imports: [
    Autocomplete,
    AutocompleteContent,
    AutocompleteEmpty,
    AutocompleteInput,
    AutocompleteItem,
    AutocompleteLabel,
    AutocompleteList,
  ],
  template: `
    <ng-container uiAutocomplete>
      <div data-slot="stack">
        <label uiAutocompleteLabel>Jump to</label>
        <input uiAutocompleteInput placeholder="e.g. Styling" />
      </div>
      <div *uiAutocompleteContent>
        <div uiAutocompleteEmpty>No sections found.</div>
        <div uiAutocompleteList>
          @for (page of pages; track page.href) {
            <a
              uiAutocompleteItem
              [value]="page.title"
              [label]="page.title"
              [href]="page.href"
            >
              {{ page.title }}
              <span data-slot="hint">{{ page.section }}</span>
            </a>
          }
        </div>
      </div>
    </ng-container>
  `,
})
class Example {
  readonly pages = [
    { title: "Installation", section: "Get Started", href: "#installation" },
    { title: "Composition", section: "Concepts", href: "#composition" },
    { title: "Build Your Own", section: "Concepts", href: "#build-your-own" },
    { title: "Styling", section: "Guides", href: "#styling" },
    { title: "API Reference", section: "Reference", href: "#api-reference" },
    { title: "Accessibility", section: "Reference", href: "#accessibility" },
  ]
}

export { Example }
```

Type “sty” and press Enter to jump to the Styling section of this page.

## Styling

Each part has a `data-slot`, such as `autocomplete-content`, and shows its state through the attributes listed under [Data Attributes](#data-attributes).

The popup exposes sizing and animation variables. `--anchor-width` is the input’s width; use `--available-height` on the content to keep a long list in the viewport.

While focus stays in the input, use the content’s `data-modality="keyboard"` with an item’s `data-highlighted` to show a keyboard focus indicator on the highlighted suggestion.

### AutocompleteContent
- `--anchor-width`: Width of the anchor, usually the trigger. Use it to match widths.
- `--anchor-height`: Height of the anchor.
- `--available-width`: Space beside the popup, up to the viewport edge. Not inherited either.
- `--available-height`: Space between the anchor and the viewport edge. Use it for max-height. Not inherited, so a child that needs it copies it on the popup, like `[--list-height:var(--available-height)]`, and reads `max-h-(--list-height)`. The first popup registers both names for the whole page with `CSS.registerProperty`, so they don't inherit anywhere. A page that needs them to inherit calls it first, with `inherits: true`. An `@property` rule can't, since a registration in script wins.
- `--transform-origin`: The point on the anchor the popup opens from. Use it to scale from the right place.
- `--arrow-offset`: Where the anchor's center falls along the popup's edge, kept `arrowPadding` from the corners. Position a ::before arrow with it.
- `--drawer-progress`: While it presents as a sheet: how far open the sheet is, from 0 closed to 1 at its largest snap point. Never past 1.
- `--drawer-dim`: While it presents as a sheet: how dim the page behind is, from 0 to 1. The backdrop's opacity follows it.
- `--drawer-expand`: While it presents as a sheet: 0 at the second-largest snap point and below, 1 at the largest. With one snap point, the whole travel.
- `--drawer-stack`: While it presents as a sheet: how many sheets opened from inside this one are open above it, rising smoothly as each one opens. Push it back with it.
- `--sheet-backdrop`: Set it yourself: the color the page dims to while it presents as a sheet. Black at 0.2 by default.

### Viewport
- `--keyboard-inset`: While it presents as a sheet: how many pixels of the page the on-screen keyboard covers, 0 without one.
- `--visual-viewport-width`: While it presents as a sheet: the width of the part of the page you can see.
- `--visual-viewport-height`: While it presents as a sheet: the height of the part of the page you can see, above the keyboard.
- `--visual-viewport-top`: While it presents as a sheet: how far the part of the page you can see is scrolled from the top of the layout, as when the keyboard pushes it up.

## Data Attributes

### AutocompleteLabel
`[data-slot="autocomplete-label"]`

- `data-disabled`: Present when the field is disabled, by its own prop, a field or a `<fieldset>`.
- `data-readonly`: Present when the field is read-only.
- `data-required`: Present when the field is required.

### AutocompleteInput
`[data-slot="autocomplete-input"]`

- `data-closed`: Present while the suggestions are closed, including while they animate out.
- `data-open`: Present while the suggestions are open.
- `data-disabled`: Present when the field is disabled, by its own prop, a field or a `<fieldset>`.
- `data-readonly`: Present when the field is read-only.
- `data-required`: Present when the field is required.

### AutocompleteTrigger
`[data-slot="autocomplete-trigger"]`

- `data-closed`: Present while the suggestions are closed, including while they animate out.
- `data-open`: Present while the suggestions are open.
- `data-disabled`: Present when the field is disabled, by its own prop, a field or a `<fieldset>`.
- `data-readonly`: Present when the field is read-only.
- `data-required`: Present when the field is required.

### AutocompleteClear
`[data-slot="autocomplete-clear"]`

- `data-disabled`: Present when the field is disabled or read-only.

### AutocompleteContent
`[data-slot="autocomplete-content"]`

- `data-closed`: Present while the suggestions are closed, including while they animate out.
- `data-presentation` (`popover`, `sheet`): How the suggestions present this time they're open.
- `data-open`: Present while the suggestions are open.
- `data-starting-style`: Present for the first frame. Style the state you animate from.
- `data-ending-style`: Present while the list animates out. Style the state you animate to.
- `data-side` (`top`, `right`, `bottom`, `left`): Where the suggestions ended up, after flipping away from edges.
- `data-align` (`start`, `center`, `end`): How the suggestions line up with the field.
- `data-modality` (`keyboard`, `pointer`): Whether the keyboard or a pointer moves the highlight. Style a focus ring for the keyboard only.
- `data-has-icons`: Present while any suggestion inside holds an icon part, so items without one can line up.

### AutocompleteItem
`[data-slot="autocomplete-item"]`

- `data-disabled`: Present when the suggestion can't be chosen. Arrow keys skip it.
- `data-highlighted`: Present on the highlighted suggestion, which Enter fills in. Focus stays in the field.
- `data-has-icon`: Present on a suggestion while it holds an icon part.

### AutocompleteItemText
`[data-slot="autocomplete-item-text"]`

- `data-matched`: Present on a suggestion's text while the field's text matched part of it, which is marked.

### AutocompleteEmpty
`[data-slot="autocomplete-empty"]`

- `data-loading`: Present while results load, with `status="loading"`.
- `data-empty`: Present while no suggestion matches.

### AutocompleteStatus
`[data-slot="autocomplete-status"]`

- `data-loading`: Present while results load, with `status="loading"`.

### AutocompleteArrow
`[data-slot="autocomplete-arrow"]`

- `data-closed`: Present while the suggestions are closed, including while they animate out.
- `data-open`: Present while the suggestions are open.
- `data-side` (`top`, `right`, `bottom`, `left`): Where the suggestions ended up, after flipping away from edges.
- `data-align` (`start`, `center`, `end`): How the suggestions line up with the field.
- `data-arrow-clamped`: Present on the arrow when it stops short of the middle of the field, held back by `arrowPadding`.

### AutocompleteItemIcon
`[data-slot="autocomplete-item-icon"]`

- `data-mirror`: Present on an icon that flips in right-to-left text, with `mirror`.

## API Reference

Each option below is an input on the directive, and each callback an output. A change callback is two outputs: `(beforeValueChange)`, with the details and `cancel()`, then `(valueChange)` with the new value alone. `value` and `open` can be bound with `[(…)]`.
`[value]` alone is a starting value the autocomplete may change until yours changes. Bind it with `[(value)]` to keep them together, or pair `[value]` with `(beforeValueChange)` and cancel the changes you don't want.

### Autocomplete

- `container?` (`DocumentFragment | Element | null`): Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
- `value?` (`string`): The text. Pass it to control it.
- `defaultValue?` (`string`): The text at first, when uncontrolled. A form reset returns to it.
- `(beforeValueChange)`: Runs when the text wants to change: typing, choosing a suggestion, a Clear part, a form reset or a controller. `details.cancel()` keeps it as it was.
- `open?` (`boolean`): Whether the suggestions are open. Pass it to control them.
- `defaultOpen?` (`boolean`): Whether the suggestions start open, when uncontrolled.
- `(beforeOpenChange)`: Runs when the suggestions want to open or close. `details.reason` says why, and `details.cancel()` stops it.
- `(openChangeComplete)`: Runs once the suggestions have finished opening or closing, after any animation.
- `(submit)`: Runs with the text when Enter is pressed with no suggestion highlighted, or after choosing one with `submitOnSelect`. The surrounding form submits next, unless the event's `preventDefault()` is called.
- `items?` (`ListData<string>`): The suggestions as data. Renders them for you, and filters them without rendering every one.
- `emptyItems?` (`ListData<string>`): Suggestions shown instead of `items` while the field is empty, like recent searches, with `openOnFocus`. Groups work, like `{ type: "group", label: "Recent", items }`. Needs `items`.
- `filter?` (`SearchFilter<string>`): How typing narrows the suggestions: `"contains"`, `"startsWith"`, `"fuzzy"`, a function of the item and the text, or `false` to keep every one, for results a server already filtered.
- `inlineComplete?` (`boolean`): Whether typing completes the text with the first suggestion that starts with it, with the rest selected after the caret: ArrowRight or End accepts it, Backspace and Escape take it back out, and arrow keys fill in the suggestion they highlight.
- `autoHighlight?` (`boolean`): Whether the first suggestion is highlighted while typing, so Enter chooses it.
- `openOnFocus?` (`boolean`): Whether the suggestions open when the field gets focus, like recent searches, even before anything is typed.
- `submitOnSelect?` (`boolean`): Whether choosing a suggestion submits, like a search box: `(submit)` runs, then the form submits.
- `status?` (`AsyncOptionsStatus`): Whether results are loading or failed, for the empty and status parts. Sets `aria-busy` on the list while loading.
- `(highlight)`: Runs when the highlight moves, with the suggestion's index among the visible ones, so a virtualized list can scroll to it.
- `(loadMore)`: Runs when the highlight or scrolling reaches the last suggestion, so the next page can load, like `createAsyncOptions`'s `loadMore`. Not again for the same suggestions, unless the last load failed.
- `announcement?` (`((change: ListAnnouncement) => string | null | undefined)`): What screen readers hear after typing pauses, when no `AutocompleteStatus` is rendered. Return null for nothing.
- `loop?` (`boolean`): Whether arrow keys wrap from the last suggestion to the first.
- `modal?` (`"pointer" | boolean`): `false`: the page stays usable while the suggestions are open. `"pointer"`: an outside press only closes them. `true`: also locks scroll and makes the rest of the page inert.
- `presentation?` (`PresentationSetting<"popover">`): How the suggestions present. `"sheet"` slides them up from the bottom of the screen with the field in its header, where they can be swiped away, and `"auto"` does that on small touch screens. A tap that opens a sheet leaves the keyboard closed until the field in the header is tapped. Decided each time they open; the server renders `"popover"` for `"auto"`.
- `disabled?` (`boolean`): Disables the field like a native input: it can't be focused or changed, and its text isn't submitted.
- `readOnly?` (`boolean`): Keeps the field focusable and its text submitted, but stops changes.
- `required?` (`boolean`): Blocks form submission while the field is empty, with the browser's own message.
- `name?` (`string`): The name the text submits under.
- `form?` (`string`): The id of a form to belong to, when the field isn't inside that form.
- `controller?` (`object`): Opens, closes, reads and sets the autocomplete from anywhere. Create one with `createAutocompleteController()`.
- `dismissible?` (`boolean`): Whether Escape, an outside press, focus or the window leaving, Android's back gesture and a sheet's swipe can close it. Triggers, Close parts and the controller always can. Pass `false` while it holds unsaved work, and ask in `(dismissAttempt)`.
- `(dismissAttempt)`: Runs when `dismissible` refused a dismissal made on purpose: Escape, an outside press, back or a swipe. Focus or the window leaving is refused without it. Ask "Discard changes?" here.
- `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.

### AutocompleteLabel

Names the input. Renders a `label` tied to the input, so you don't need a `uiField`.

### AutocompleteInput

The text field. Goes on an `input` and gets the combobox role.

### AutocompleteTrigger

An optional button that opens and closes the suggestions. Goes on a `button`.

### AutocompleteClear

- `keepMounted?` (`boolean`): Whether the clear button stays in the page while the field is empty.

### AutocompleteContent

- `side?` (`Side`): Which side of the anchor the popup opens on. Flips to the other side when there isn't room. Which side of the field the suggestions open on.
- `align?` (`Align`): How the popup lines up with the anchor along that side. `start` and `end` follow the reading direction. How the suggestions line up with the field along that side.
- `sideOffset?` (`number`): Gap between the anchor and the popup, in pixels. Gap between the field and the suggestions, in pixels.
- `alignOffset?` (`number`): Shift along the anchor, in pixels. Shift along the field, in pixels.
- `collisionPadding?` (`number`): Space to keep from the viewport edges, in pixels.
- `arrowPadding?` (`number`): Space to keep between the arrow and the popup's corners, in pixels.
- `anchor?` (`string | Anchor | null`): Positions the popup against this instead of its trigger: an element, a CSS selector, a point like `{ x, y }`, or anything with `getBoundingClientRect()`. It's read on every check, so it can move. A controller's `open({ anchor })` wins for that open.
- `container?` (`DocumentFragment | Element | null`): Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
- `keepMounted?` (`boolean`): Whether the suggestions stay in the page, hidden, while closed.

### AutocompleteArrow

An optional arrow pointing at the input. Renders a `div` positioned on the content's edge.

### AutocompleteStatus

Announces loading and result counts to screen readers. Its content is yours, read from its `state()`.

### AutocompleteEmpty

Shows when no suggestion matches. Its content is yours, read from its `state()`.

### AutocompleteList

Holds the suggestions and gets the listbox role. Put `uiAutocompleteItems` inside it to render `items`.

### AutocompleteGroup

Groups related suggestions. Gets the group role.

### AutocompleteGroupLabel

Names its group. Renders a `div` the group is labelled by.

### AutocompleteItem

- `value` (`string`): Identifies the suggestion. Choosing it fills the field with its `label`, or with this when there's none.
- `label?` (`string`): The text the field gets and filtering matches, when the content isn't plain text. Not the accessible name: use `aria-label` for that.
- `keywords?` (`string[]`): More words filtering matches.
- `disabled?` (`boolean`): Keeps the suggestion from being chosen. Sets `data-disabled` and `aria-disabled`.
- `index?` (`number`): The suggestion's position among all visible ones, for virtualized lists that render only some. Sets `aria-posinset` and `aria-setsize`.

### AutocompleteItemIcon

- `mirror?` (`boolean`): Flips the icon horizontally in right-to-left text, for icons that point a way, like arrows and chevrons. Icons that picture a thing, like a clock or a check, stay as they are.

### AutocompleteItemText

The suggestion's text, with the matched part marked. Its `state()` holds the matched `segments`.

### AutocompleteSeparator

A divider between suggestions or groups. Gets the separator role.

### Items as Data

Each suggestion in `items`, or a plain string. Groups are `{ type: "group", label, items }` and separators `{ type: "separator" }`.

- `value` (`T`): Identifies the item, and is what choosing it reports. A string, or any value with `itemToValue`.
- `label` (`string`): The text shown and matched by typeahead and filtering. A select's trigger shows it once chosen.
- `keywords?` (`string[]`): More words filtering matches, like `["team"]` for a plan called Pro.
- `disabled?` (`boolean`): Keeps the item from being chosen. The keyboard skips it, like in a native select.

### State

What each part's `state()` signal holds, per part.

`uiAutocompleteInput` and `uiAutocompleteTrigger`:

- `open` (`boolean`): Whether the suggestions are open.
- `disabled` (`boolean`): Whether the field is disabled, by itself or by a `<fieldset>`.
- `readOnly` (`boolean`): Whether the field is read-only.
- `required` (`boolean`): Whether the field is required.

`uiAutocompleteContent` and `uiAutocompleteList`:

- `open` (`boolean`): Whether the suggestions are open. False while they animate out.
- `presentation` (`"popover" | "sheet"`): How they present this time they're open.
- `status` (`AsyncOptionsStatus`): Whether results are loading or failed.
- `items` (`ListData<string>`): The visible suggestions, for rendering a virtualized list yourself.

`uiAutocompleteItem`:

- `highlighted` (`boolean`): Whether the suggestion is highlighted, by the keyboard or the pointer.
- `disabled` (`boolean`): Whether the suggestion can't be chosen.

`uiAutocompleteEmpty`:

- `loading` (`boolean`): Whether results are loading.
- `empty` (`boolean`): Whether no item matches.
- `query` (`string`): The text the list is filtered by.

`uiAutocompleteStatus`:

- `status` (`"idle" | "loading" | "error"`): Whether results are loading or failed.
- `loading` (`boolean`): Whether results are loading.
- `count` (`number`): How many items are visible.

`uiAutocompleteClear`:

- `disabled` (`boolean`): Whether the field is disabled or read-only.

`uiAutocompleteArrow`:

- `open` (`boolean`): Whether the suggestions are open.

`uiAutocompleteItemText`, which takes no inputs of its own:

- `segments` (`MatchSegment[]`): The text in pieces, each marked when it matched. Joined, they're the whole text.
- `matched` (`boolean`): Whether any piece matched.

`uiAutocompleteItemIcon`:

- `mirror` (`boolean`): Whether it flips in right-to-left text.

### Reasons

Why the text changed:

- `input-change` (`Event`): Typing, pasting or dropping changed a text field's value; in a combobox it can also open or close it, or Enter keeps the typed text as the value.
- `item-press` (`MouseEvent | KeyboardEvent`): A member of a collection was chosen: a menu item, a tab, a radio or a checkbox item.
- `list-navigation` (`KeyboardEvent`): Arrow, Home or End keys moved the selection, typing picked an item, or Ctrl or ⌘ with A selected every item of a listbox.
- `escape-key` (`KeyboardEvent`): Escape, or a submenu's close key (ArrowLeft in left-to-right layouts).
- `clear-press` (`MouseEvent | KeyboardEvent`): A Clear part was pressed, like on an input, a select or a combobox.
- `reset` (`none`): A form reset.
- `imperative` (`none`): A controller or `api` call.

And why the suggestions opened or closed:

- `input-change` (`Event`): Typing, pasting or dropping changed a text field's value; in a combobox it can also open or close it, or Enter keeps the typed text as the value.
- `item-press` (`MouseEvent | KeyboardEvent`): A member of a collection was chosen: a menu item, a tab, a radio or a checkbox item.
- `escape-key` (`KeyboardEvent`): Escape, or a submenu's close key (ArrowLeft in left-to-right layouts).
- `imperative` (`none`): A controller or `api` call.
- `trigger-press` (`MouseEvent | KeyboardEvent | TouchEvent`): Click, tap, Enter or Space on the part that opens, closes or toggles. Arrow keys that open a menu or submenu count too. A tap on a combobox's input that opens a sheet reports its `touchend`.
- `trigger-focus` (`FocusEvent`): Keyboard focus reached a trigger that opens on focus, like a tooltip's.
- `input-commit` (`KeyboardEvent | FocusEvent`): Enter, or leaving a number input, committed what was typed: a number input parses, clamps and snaps it to the step, and an autocomplete closes its suggestions on it.
- `outside-press` (`MouseEvent`): A press outside the layer.
- `close-press` (`MouseEvent | KeyboardEvent | SubmitEvent`): A Close part was pressed, or a form with `method="dialog"` was submitted.
- `focus-out` (`KeyboardEvent | FocusEvent`): Focus left the layer, or Tab moved it out.
- `window-blur` (`FocusEvent`): The window lost focus.
- `back` (`Event`): Going back: the Android back button or gesture, or Backspace in an empty command input, which returns to the previous page.
- `swipe` (`TouchEvent | PointerEvent`): A swipe gesture: a finger, mouse or pen dragged it.
- `anchor-hidden` (`none`): The element the popup sits beside stopped rendering, like a trigger a breakpoint hides.

With `dismissible` false, the refused dismissals `(dismissAttempt)` reports:

- `escape-key` (`KeyboardEvent`): Escape, or a submenu's close key (ArrowLeft in left-to-right layouts).
- `outside-press` (`MouseEvent`): A press outside the layer.
- `back` (`Event`): Going back: the Android back button or gesture, or Backspace in an empty command input, which returns to the previous page.
- `swipe` (`TouchEvent | PointerEvent`): A swipe gesture: a finger, mouse or pen dragged it.

### Controller

Create one with `createAutocompleteController()` and pass it as `controller`.

- `isOpen()` (`() => boolean`): Whether the suggestions are open.
- `setOpen(open, options?)` (`(open: boolean, options?: AutocompleteChangeOptions<AutocompleteOpenChangeReason> | undefined) => boolean`): Opens or closes the suggestions. Returns false when the change was canceled or it was already open or closed.
- `open(options?)` (`(options?: (AutocompleteChangeOptions<AutocompleteOpenChangeReason> & { signal?: AbortSignal | undefined; }) | undefined) => Promise<...>`): Opens the suggestions, and resolves once they close, with why and how. Resolves exactly once and never rejects: on the next close, when `signal` aborts, or with reason `"unmount"`.
- `close(options?)` (`(options?: AutocompleteChangeOptions<AutocompleteOpenChangeReason> | undefined) => boolean`): Closes the suggestions. Returns false when the close was canceled or it was already closed.
- `toggle(options?)` (`(options?: AutocompleteChangeOptions<AutocompleteOpenChangeReason> | undefined) => boolean`): Opens the suggestions when they're closed, and closes them when they're open. Returns false when the change was canceled.
- `getValue()` (`() => string`): The text.
- `setValue(value, options?)` (`(value: string, options?: AutocompleteChangeOptions<AutocompleteValueChangeReason> | undefined) => boolean`): Changes the text, which filters the suggestions. Returns false when the change was canceled or nothing changed.
- `clear(options?)` (`(options?: AutocompleteChangeOptions<AutocompleteValueChangeReason> | undefined) => boolean`): Empties the field. Returns false when the change was canceled or nothing changed.
- `getHighlighted()` (`() => string | null`): The value of the highlighted suggestion, or null when none is.
- `highlight(value)` (`(value: string | null) => boolean`): Highlights the suggestion with this value in the open list, scrolled into view, or none with null. Returns false when the suggestions are closed, or no enabled suggestion has the value.
- `focus()` (`() => void`): Moves focus to the field.

### Events

A `before` output emits `{ value, reason, event, cancel() }` before the change, and its plain output follows with the value alone. A bound value only updates when the change isn't canceled.

| Binding                | On               | Receives                                                                                               |
| ---------------------- | ---------------- | ------------------------------------------------------------------------------------------------------ |
| `[(value)]`            | `uiAutocomplete` | The text                                                                                               |
| `[(open)]`             | `uiAutocomplete` | Whether the suggestions are open                                                                       |
| `(beforeValueChange)`  | `uiAutocomplete` | `{ value, reason, cancel() }`: the new text, the [reason](#reasons) and whether it's still `composing` |
| `(beforeOpenChange)`   | `uiAutocomplete` | `{ value, reason, cancel() }`: the new state, and the [reason](#reasons)                               |
| `(openChangeComplete)` | `uiAutocomplete` | `$event`, whether it's open, after the animation                                                       |
| `(submit)`             | `uiAutocomplete` | `{ value, event }`: the text, when Enter submits                                                       |
| `(highlight)`          | `uiAutocomplete` | `{ value, index, event }`: the highlighted suggestion                                                  |
| `(loadMore)`           | `uiAutocomplete` | `()`, when the last suggestion is reached                                                              |
| `(dismissAttempt)`     | `uiAutocomplete` | `{ reason, event }`, when a dismissal was refused                                                      |

## Accessibility

The autocomplete follows the [WAI-ARIA combobox pattern with list autocomplete](https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-autocomplete-list/), and [list and inline](https://www.w3.org/WAI/ARIA/apg/patterns/combobox/examples/combobox-autocomplete-both/) with `inlineComplete`.

Typing filters the suggestions. Arrow keys move the highlight; Enter fills in the highlighted text and Escape closes the list. Focus usually stays in the input while `aria-activedescendant` identifies the highlighted suggestion. A touch screen-reader trigger can move focus into the list, and a sheet has its own [focus behavior](#presentation).

Every line below is an automated test.

**Field**

- Is a combobox named by its label, with list autocomplete.
- Typing opens the suggestions that match, and the text stays what was typed.
- Text that matches nothing stays, with the empty message.
- Typing in the middle of the text keeps the caret where it was.

**Choosing**

- Arrow keys move the highlight while focus stays in the field.
- Enter fills in the highlighted suggestion and closes, without submitting.
- Clicking a suggestion fills it in and keeps focus in the field.
- A disabled suggestion can't be chosen.
- Escape takes an inline completion back out.
- Escape closes the suggestions and keeps the text.

**Forms**

- Enter with nothing highlighted submits the text as typed.
- The field submits a chosen suggestion's text under its name.
- Required blocks submitting an empty field.
- A disabled field can't be focused or changed.

**Clear**

- The clear button empties the field and keeps focus in it.

Runs in React, Vue and web components.

Also tested:

**Enhancements**

- Inline completion fills in the first match with the rest selected after the caret.
- Backspace takes an inline completion out and doesn't complete again.
- ArrowRight accepts an inline completion.
- With inline completion, arrow keys fill in the suggestion they highlight.
- The suggestions open when the field gets focus.
- Enter with nothing highlighted runs onSubmit with the text.
- Filtering matches a suggestion's keywords.
- A form reset puts the default text back.
- The list is named by the field's label.
- An immediate search runs once when the autocomplete mounts.
- A newer search aborts the older one, and only its results land.
- Arrow keys keep the highlighted item in view when the … scrolls.

Runs in React, Vue and web components.

Screen readers hear the same thing in each tested framework, recorded by a virtual screen reader:

- Announcements while typing and choosing with a keyboard.

Runs in React, Vue and web components.
