Autocomplete

Autocomplete input and dropdown selection with filtering options.

Default

Standard autocomplete with filtering.

With Clear Button

Autocomplete input with an optional clear button.

With Groups

Display options grouped by category.

Object Values (Custom Label)

Handling complex objects by providing a custom itemToString function.

Async Search

Loading and filtering options from an external data source.

Installation & Usage

Installation

ng g @spartan-ng/cli:ui autocomplete

Imports

import { HlmAutocompleteImports } from '@spartan-ng/helm/autocomplete';

Basic Skeleton

<hlm-autocomplete [(search)]="search">
  <hlm-autocomplete-input placeholder="Search..." />
  <hlm-autocomplete-content *hlmAutocompletePortal>
    <hlm-autocomplete-empty>No results found.</hlm-autocomplete-empty>
    <div hlmAutocompleteList>
      @for (option of filteredOptions(); track option) {
        <hlm-autocomplete-item [value]="option">{{ option }}</hlm-autocomplete-item>
      }
    </div>
  </hlm-autocomplete-content>
</hlm-autocomplete>

API Reference

Brain API

The brain directives provide the functional logic and state management for the autocomplete.

DirectiveSelectorInputs / Outputs
BrnAutocomplete[brnAutocomplete]
  • search: string (Two-way binding)
  • itemToString: (item: T) => string
  • isItemEqualToValue: (item: T, value: T) => boolean
BrnAutocompleteTrigger[brnAutocompleteTrigger]Trigger for opening the autocomplete content.

Helm API

The helm components provide the default spartan/ui styling.

Component / DirectiveSelectorDescription
HlmAutocompleteComponenthlm-autocompleteMain container component.
HlmAutocompleteInputDirectivehlm-autocomplete-inputStyled input field. Inputs: showClear: boolean.
HlmAutocompleteContentDirectivehlm-autocomplete-contentThe overlay container.
HlmAutocompleteItemDirectivehlm-autocomplete-itemIndividual option item. Input: value: T.