Skip to content
design
Components

Autocomplete

A text input whose suggestions do not restrict what can be entered.

On this page

Custom audience names are allowed.

A text input whose suggestions do not restrict what can be entered.
Code
import { Autocomplete } from "@bosunkit/components/autocomplete";
import { Field } from "@bosunkit/components/field";
import type { ReactElement } from "react";
const items: readonly string[] = ["Engineering", "Product", "Investors"];
export const description: string =
  "Choose a familiar audience or enter another name; the value remains the input text.";
export default function Showcase(): ReactElement {
  return (
    <Field.Root>
      <Field.Label>Audience</Field.Label>
      <Autocomplete.Root items={items}>
        <Autocomplete.Input placeholder="Choose or type an audience" />
        <Autocomplete.Portal>
          <Autocomplete.Positioner sideOffset={4}>
            <Autocomplete.Popup>
              <Autocomplete.List>
                {(item: string): ReactElement => (
                  <Autocomplete.Item key={item} value={item}>
                    {item}
                  </Autocomplete.Item>
                )}
              </Autocomplete.List>
            </Autocomplete.Popup>
          </Autocomplete.Positioner>
        </Autocomplete.Portal>
      </Autocomplete.Root>
      <Field.Description>Custom audience names are allowed.</Field.Description>
    </Field.Root>
  );
}
01Names describe behaviorUse the primitive for custom composition and a named recipe for an assembled control.
02One state contractControlled values, defaults and change callbacks follow Base UI; event details keep their reason and cancellation.
03Composition keeps semanticsA render target forwards its ref and every received DOM prop so keyboard interaction and accessible names survive.

Composition

Import { Autocomplete } from @bosunkit/components/autocomplete. Named parts follow Base UI Autocomplete. Each part retains the upstream render, ref, DOM props, state attributes and event contracts. The kit supplies its typography, surfaces and scoped overlay presentation.

Examples

Custom composition

Custom audience names are allowed.

Choose a familiar audience or enter another name; the value remains the input text.
Code
import { Autocomplete } from "@bosunkit/components/autocomplete";
import { Field } from "@bosunkit/components/field";
import type { ReactElement } from "react";
const items: readonly string[] = ["Engineering", "Product", "Investors"];
export const description: string =
  "Choose a familiar audience or enter another name; the value remains the input text.";
export default function Showcase(): ReactElement {
  return (
    <Field.Root>
      <Field.Label>Audience</Field.Label>
      <Autocomplete.Root items={items}>
        <Autocomplete.Input placeholder="Choose or type an audience" />
        <Autocomplete.Portal>
          <Autocomplete.Positioner sideOffset={4}>
            <Autocomplete.Popup>
              <Autocomplete.List>
                {(item: string): ReactElement => (
                  <Autocomplete.Item key={item} value={item}>
                    {item}
                  </Autocomplete.Item>
                )}
              </Autocomplete.List>
            </Autocomplete.Popup>
          </Autocomplete.Positioner>
        </Autocomplete.Portal>
      </Autocomplete.Root>
      <Field.Description>Custom audience names are allowed.</Field.Description>
    </Field.Root>
  );
}

Props

PropTypeDefaultDescription
disabledboolean | undefined–Whether the component should ignore user interaction.
classNamestring | ((state: State) => string | undefined) | undefined–CSS class applied to the element, or a function that returns a class based on the component's state.
renderReact.ReactElement | ComponentRenderFn<RenderFunctionProps, State> | undefined–Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
styleReact.CSSProperties | ((state: State) => React.CSSProperties | undefined) | undefined–Style applied to the element, or a function that returns a style object based on the component's state.

Also takes every attribute of Primitive.Input.Props.

PropTypeDefaultDescription
initialFocusboolean | React.RefObject<HTMLElement | null> | ((openType: InteractionType) => void | boolean | HTMLElement | null) | undefined–Determines the element to focus when the popup is opened. - false: Do not move focus. - true: Move focus based on the default behavior (first tabbable element or popup). - RefObject: Move focus to the ref element. - function: Called with the interaction type (mouse, touch, pen, or keyboard). Return an element to focus, true to use the default behavior, or false/undefined to do nothing.
finalFocusboolean | React.RefObject<HTMLElement | null> | ((closeType: InteractionType) => void | boolean | HTMLElement | null) | undefined–Determines the element to focus when the popup is closed. - false: Do not move focus. - true: Move focus based on the default behavior (trigger or previously focused element). - RefObject: Move focus to the ref element. - function: Called with the interaction type (mouse, touch, pen, or keyboard). Return an element to focus, true to use the default behavior, or false/undefined to do nothing.
classNamestring | ((state: State) => string | undefined) | undefined–CSS class applied to the element, or a function that returns a class based on the component's state.
renderReact.ReactElement | ComponentRenderFn<RenderFunctionProps, State> | undefined–Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
styleReact.CSSProperties | ((state: State) => React.CSSProperties | undefined) | undefined–Style applied to the element, or a function that returns a style object based on the component's state.

Also takes every attribute of Primitive.Popup.Props.

PropTypeDefaultDescription
childrenReact.ReactNode–
onClickBaseUIComponentProps<'div', AutocompleteItemState>['onClick'] | undefined–An optional click handler for the item when selected. It fires when clicking the item with the pointer, as well as when pressing Enter with the keyboard if the item is highlighted when the Input or List element has focus.
indexnumber | undefined–The index of the item in the list. Improves performance when specified by avoiding the need to calculate the index automatically from the DOM.
valueany–A unique value that identifies this item.
disabledboolean | undefined–Whether the component should ignore user interaction.
classNamestring | ((state: State) => string | undefined) | undefined–CSS class applied to the element, or a function that returns a class based on the component's state.
renderReact.ReactElement | ComponentRenderFn<RenderFunctionProps, State> | undefined–Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
styleReact.CSSProperties | ((state: State) => React.CSSProperties | undefined) | undefined–Style applied to the element, or a function that returns a style object based on the component's state.
nativeButtonboolean | undefined–Whether the component renders a native <button> element when replacing it via the render prop. Set to true if the rendered element is a native button.

Also takes every attribute of Primitive.Item.Props.

PropTypeDefaultDescription
childrenReact.ReactNode | ((item: any, index: number) => React.ReactNode)–
classNamestring | ((state: State) => string | undefined) | undefined–CSS class applied to the element, or a function that returns a class based on the component's state.
renderReact.ReactElement | ComponentRenderFn<RenderFunctionProps, State> | undefined–Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.
styleReact.CSSProperties | ((state: State) => React.CSSProperties | undefined) | undefined–Style applied to the element, or a function that returns a style object based on the component's state.

Also takes every attribute of Primitive.List.Props.

Asynchronous suggestions

The lookup is caller-owned and abortable; this local specimen returns suggestions without a network request.
Code
import { AsyncAutocomplete, type Suggestion } from "@bosunkit/components/autocomplete";
import { FormField } from "@bosunkit/components/form-field";
import type { ReactElement } from "react";
export const description: string =
  "The lookup is caller-owned and abortable; this local specimen returns suggestions without a network request.";
export default function AsyncExample(): ReactElement {
  return (
    <FormField label="Audience">
      <AsyncAutocomplete
        minQueryLength={1}
        suggest={(query: string): Promise<readonly Suggestion[]> =>
          Promise.resolve(
            ["Engineering", "Product", "Investors"]
              .filter((label: string): boolean => label.toLowerCase().includes(query.toLowerCase()))
              .map((label: string): Suggestion => ({ label, value: label })),
          )
        }
      />
    </FormField>
  );
}

AsyncAutocomplete accepts suggest(query, signal) and minQueryLength. The caller owns the lookup; superseded requests are aborted and late answers are ignored. The callback keeps Base UI's cancellable event details.

PropTypeDefaultDescription
suggestrequired(query: string, signal: AbortSignal) => Promise<readonly Suggestion[]>–Caller-owned asynchronous lookup; no transport belongs to the kit.
minQueryLengthnumber | undefined–Minimum trimmed query length.
itemToStringValue((item: Suggestion) => string) | undefined(item: Suggestion): string => item.labelText inserted when choosing a suggestion; display label by default.
valuestring | undefined–Text value; arbitrary text remains valid.
defaultValuestring | undefined–Initial text when uncontrolled.
onValueChangeBase.Root.Props<Suggestion>["onValueChange"]–Original cancellable Base UI text-change event.
onBlurBase.Input.Props["onBlur"]–Input blur handler, preserving the native focus event.
idstring | undefined–Control ID for an external label.
aria-labelstring | undefined–Accessible control name when no visible label is associated.
aria-describedbystring | undefined–Hint and error element IDs.
placeholderstring | undefined–Input placeholder.
readOnlyboolean | undefined–Prevent editing.
disabledboolean | undefined–Prevent interaction and form submission.
namestring | undefined–Submitted field name.
motionboolean | undefinedtrueEnable popup entrance motion.
classNamestring | undefined–Input classes.
refRef<HTMLInputElement> | undefined–Input element.
Do

Custom audience names are allowed.

Compose labeled parts and preserve their ref and DOM props.
Don't
Use the named parts for keyboard and focus behavior.
Do not replace semantic controls with clickable generic elements or discard event details.