Skip to content
// EFFECT DAYS 2026

ListNavigation unstable

Moves an index across a list of items in response to arrow keys, Home and End, respecting orientation, text direction and looping.

Details

step and target return indexes; the caller moves focus or updates a highlight such as aria-activedescendant. Filter disabled items with available before calculating indexes.

Example Navigating a horizontal right-to-left list

import { ListNavigation } from "effect/ui/kit"
const items = [
{ value: "a" },
{ value: "b", disabled: true },
{ value: "c" }
].filter(ListNavigation.available)
const next = ListNavigation.target("ArrowLeft", {
at: 0,
last: items.length - 1,
orientation: "horizontal",
rtl: true,
loop: "wrap"
})
if (next !== 1 || items[next]?.value !== "c") {
throw new Error("ArrowLeft in RTL should move from a to c")
}
12 exports Since v4.2.0 Source

Guards

available

unstable
Since v4.2.0

Returns true when an item is defined and not disabled.

Signature

declare function available<A extends {
readonly disabled?: boolean;
}>(item: A | undefined): item is A

isKey

unstable
Since v4.2.0

Returns true when a keydown payload is an unmodified, non-composing navigation key (Home, End, or the arrow keys for orientation).

Details

Use it in a view or parts keydown handler with { preventDefault: true } to cancel the browser default only for matching keys.

Signature

declare function isKey(event: KeyEvent, orientation: "horizontal" | "vertical"): boolean

Models

ArrowKeys

interface unstable
Since v4.2.0

The KeyboardEvent.key names for moving forward and backward along an axis.

Signature

interface ArrowKeys {
readonly next: string;
readonly previous: string;
}

KeyEvent

type unstable
Since v4.2.0

The subset of Html.KeyPayload that isKey inspects.

Signature

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

Loop

type unstable
Since v4.2.0

What step and target do at the ends of a list.

Signature

type Loop = typeof Loop.Type

Orientation

type unstable
Since v4.2.0

The axis a list runs along.

Signature

type Orientation = typeof Orientation.Type

TargetOptions

interface unstable
Since v4.2.0

Options for target.

Details

  • at: the current index, or -1 when no item is active.
  • last: the last valid index (items.length - 1), or -1 for an empty list.
  • orientation: "vertical" by default.
  • rtl: swaps ArrowLeft and ArrowRight when orientation is "horizontal". false by default.
  • loop: "wrap" by default.

Signature

interface TargetOptions {
readonly at: number;
readonly last: number;
readonly loop?: "none" | "wrap" | "escape";
readonly orientation?: "horizontal" | "vertical";
readonly rtl?: boolean;
}

Navigation

arrowKeys

unstable
Since v4.2.0

Returns the next and previous arrow key names for an orientation and reading direction.

Signature

declare function arrowKeys(orientation: "horizontal" | "vertical", rtl: boolean): ArrowKeys

step

unstable
Since v4.2.0

Moves an index by one step (1 or -1) within [0, last], following loop at the ends. Returns -1 when last < 0 or when loop is "escape" and the step leaves the list.

Signature

declare function step(at: number, last: number, direction: -1 | 1, loop: "none" | "wrap" | "escape"): number

target

unstable
Since v4.2.0

Resolves a key press to the next list index, or undefined when key is not a navigation key for the given orientation.

Details

Handles Home, End, and the arrow keys of orientation (swapped when rtl is true for "horizontal"). Returns -1 when the list is empty (last < 0) or when loop is "escape" and the press leaves the list.

Signature

declare function target(key: string, options: TargetOptions): number | undefined

Schemas

Loop

unstable
Since v4.2.0

What step and target do at the ends of a list.

Details

  • "none": stay on the first or last item.
  • "wrap": jump from the last item to the first and back.
  • "escape": return -1 past either end, so a highlight can clear before entering the other end on the next press.

Signature

declare const Loop: Literals<readonly ["none", "wrap", "escape"]>

Orientation

unstable
Since v4.2.0

The axis a list runs along, which decides which arrow keys move through it.

Signature

declare const Orientation: Literals<readonly ["horizontal", "vertical"]>