Autocomplete

An input that suggests options as you type.

Installation

Install the component package, shared coss-svelte theme, and Bits UI peer.

npm install coss-svelte @coss-svelte/theme bits-ui

Usage

Import the Svelte component exports directly from the package.

import { Autocomplete, AutocompleteCollection, AutocompleteEmpty, AutocompleteGroup, AutocompleteGroupLabel, AutocompleteInput, AutocompleteItem, AutocompleteList, AutocompletePopup, AutocompleteSeparator, AutocompleteStatus } from "coss-svelte";

Anatomy

  • Autocomplete
  • AutocompleteCollection
  • AutocompleteEmpty
  • AutocompleteGroup
  • AutocompleteGroupLabel
  • AutocompleteInput
  • AutocompleteItem
  • AutocompleteList
  • AutocompletePopup
  • AutocompleteSeparator
  • AutocompleteStatus

API Reference

Autocomplete

An input that suggests options as you type.

Signatures

{ type?: "single"; value?: string; onValueChange?: OnChangeFn<string> }{ type: "multiple"; value?: string[]; onValueChange?: OnChangeFn<string[]> }
PropTypeDefaultDescription
type"single" | "multiple""single"Behavior, selection, or HTML type passed to the underlying control.
bind:valuestring | string[]""Current value for the component. Bind with `bind:value` when supported.
bind:openbooleanfalseOpen state for the popup or disclosure. Bind with `bind:open`.
optionsOption[][]Options rendered by the component's built-in fallback composition.
placeholderstring"Search"Placeholder text shown by the built-in input.
children : Snippet<[]>

Inherits from Bits UI Combobox.Root and Bits UI Combobox.Input.

AutocompleteCollection

Connects repeated items to the parent collection state.

children : Snippet<[]>

Inherits from Svelte component attributes.

AutocompleteEmpty

Renders fallback content when the collection has no results.

children : Snippet<[]>

Inherits from Svelte component attributes.

AutocompleteGroup

Groups related items inside the parent component.

children : Snippet<[]>bind:ref : HTMLElement | null

Inherits from Bits UI Combobox.Group.

AutocompleteGroupLabel

Labels a group of related items.

children : Snippet<[]>bind:ref : HTMLElement | null

Inherits from Bits UI Combobox.GroupHeading.

AutocompleteInput

Renders the input field for the parent component.

PropTypeDefaultDescription
showTriggerbooleanfalseShows a trigger button beside the input.
triggerProps(Omit<{}, "child" | "children"> & { child?: Snippet<[{ props: Record<string, unknown> }]> | undefined; children?: Snippet<[]> | undefined; style?: StyleProperties | string | null | undefined; ref?: HTMLElement | null | undefined } & Without<BitsPrimitiveButtonAttributes, SelectTriggerPropsWithoutHTML>){}Props forwarded to the optional trigger button.
bind:ref : HTMLElement | null

Inherits from Bits UI Combobox.Input and Bits UI Combobox.Trigger.

AutocompleteItem

Renders one selectable or repeated item.

children : Snippet<[]>bind:ref : HTMLElement | null

Inherits from Bits UI Combobox.Item.

AutocompleteList

Wraps a list of related items.

children : Snippet<[]>bind:ref : HTMLElement | null

Inherits from Bits UI Combobox.Viewport.

AutocompletePopup

Renders the floating or modal surface for the parent component.

PropTypeDefaultDescription
portalProps{ disabled?: boolean; to?: PortalTarget }{}Configures the exact Bits Portal target (`to`) or renders inline when `disabled`.
children : Snippet<[]>bind:ref : HTMLElement | null

Inherits from Bits UI Combobox.Content.

AutocompleteSeparator

Visually separates related content.

children : Snippet<[]>bind:ref : HTMLElement | null

Inherits from Bits UI Combobox.Separator.

AutocompleteStatus

Renders status text for the current collection state.

children : Snippet<[]>

Inherits from Svelte component attributes.

Implementation Details

Status
Stable
Foundation
compound
Category
Selection & Input
Particles
15