Skip to content
// EFFECT DAYS 2026

Typeahead unstable

Matches typed prefixes against enabled items in a labelled list, with repeated-letter cycling. Use it to add type-to-jump navigation to a picker.

Details

Keep Typeahead.State in your component's Model, call Typeahead.step in update, and use Typeahead.waitReset to send a message that resets the buffer after a pause.

Example Typing to jump and cycling on repeated letters

import { Typeahead } from "effect/ui/kit"
const items = [
{ label: "Apple" },
{ label: "Apricot", disabled: true },
{ label: "Avocado" },
{ label: "Banana" }
]
const first = Typeahead.step(Typeahead.initial, "a", items, -1)
if (first.index !== 0) throw new Error("should match Apple")
// Repeating the same letter cycles past disabled Apricot to Avocado.
const second = Typeahead.step(first.state, "a", items, first.index)
if (second.index !== 2) throw new Error("should cycle to Avocado")
// Resetting clears the buffer so typing starts fresh.
const cleared = Typeahead.reset(second.state)
if (Typeahead.isTyping(cleared)) throw new Error("buffer should be cleared")
12 exports Since v4.2.0 Source

Commands

waitReset

unstable
Since v4.2.0

Creates a Command that sends onComplete's message after delay milliseconds (default: 750). Running it again restarts the timer.

Signature

declare function waitReset<Msg>(onComplete: () => Msg, delay?: number): Issued<Msg, never>

WaitReset

unstable
Since v4.2.0

The reset timer Command. In stories, resolve it with .resolve(Typeahead.WaitReset, undefined).

Details

Waits delay milliseconds (750 ms when omitted). Each new run interrupts the previous one in the same component instance.

Signature

declare const WaitReset: Command.Factory<{
readonly delay?: number;
}, void>

Constants

initial

unstable
Since v4.2.0

The initial empty State.

Signature

declare const initial: State

Guards

isPrintable

unstable
Since v4.2.0

Returns true when a keydown payload is a single printable character that is not part of an IME composition and has no Alt, Ctrl or Meta modifier.

Signature

declare function isPrintable(event: KeyEvent): boolean

isTyping

unstable
Since v4.2.0

Returns true while characters are buffered in state.

Details

Use it to distinguish a Space pressed mid-word (part of typeahead) from a standalone Space (which activates the highlighted item or opens a trigger).

Signature

declare function isTyping(state: {
readonly matched: number;
readonly typed: string;
readonly typedFrom: number;
}): boolean

Matching

reset

unstable
Since v4.2.0

Clears the buffered text so the next key starts a fresh search.

Signature

declare function reset(state: {
readonly matched: number;
readonly typed: string;
readonly typedFrom: number;
}): {
readonly matched: number;
readonly typed: string;
readonly typedFrom: number;
}

step

unstable
Since v4.2.0

Appends key to the buffer and returns the next state and matching index (-1 if no item matches). A new search starts after from (the start of items when from is -1).

Details

Matching is case-insensitive and skips disabled items. Pressing the same single letter repeatedly cycles through items starting with that letter, unless an enabled item's label begins with that letter doubled (such as "Aaron"). A space that fails to extend a match is kept in the buffer so multi-word labels can still match; any other unmatched key clears it.

Signature

declare function step(state: {
readonly matched: number;
readonly typed: string;
readonly typedFrom: number;
}, key: string, items: readonly Array<Item>, from: number): Step

Models

Item

interface unstable
Since v4.2.0

A labelled item for step. Disabled items are skipped.

Signature

interface Item {
readonly disabled?: boolean;
readonly label: string;
}

KeyEvent

type unstable
Since v4.2.0

The subset of Html.KeyPayload that isPrintable inspects.

Signature

type KeyEvent = Pick<Html.KeyPayload, "key" | "alt" | "ctrl" | "meta" | "composing">

State

type unstable
Since v4.2.0

The typeahead buffer stored in a component's Model.

Signature

type State = typeof State.Type

Step

interface unstable
Since v4.2.0

The result of step: the next State to store in the Model, and index, the index of the matched item in items or -1 when nothing matched.

Signature

interface Step {
readonly index: number;
readonly state: {
readonly matched: number;
readonly typed: string;
readonly typedFrom: number;
};
}

Schemas

State

unstable
Since v4.2.0

The typeahead buffer stored in a component's Model.

Signature

declare const State: Struct<{
readonly matched: Number;
readonly typed: String;
readonly typedFrom: Number;
}>