Choose one or several options from an always-visible list.

Use a Listbox when the choices should stay in view. It works like a native select with several visible rows, with keyboard navigation, typeahead, and optional range selection.

import { Component } from "@angular/core"
import { LucideCheck } from "@lucide/angular"
import { Field, FieldDescription, FieldLabel } from "@ui-sdk/angular/field"
import {
  Listbox,
  ListboxItem,
  ListboxItemIndicator,
} from "@ui-sdk/angular/listbox"

@Component({
  imports: [
    Field,
    FieldDescription,
    FieldLabel,
    Listbox,
    ListboxItem,
    ListboxItemIndicator,
    LucideCheck,
  ],
  template: `
    <div uiField>
      <label uiFieldLabel>Email me about</label>
      <div
        uiListbox
        multiple
        activation="automatic"
        [defaultValue]="['mentions']"
      >
        @for (topic of topics; track topic.value) {
          <div uiListboxItem [value]="topic.value">
            {{ topic.label }}
            <span *uiListboxItemIndicator>
              <svg lucideCheck></svg>
            </span>
          </div>
        }
      </div>
      <p uiFieldDescription>
        Hold Shift to select a range, or Ctrl or โŒ˜ to add one.
      </p>
    </div>
  `,
})
class Example {
  readonly topics = [
    { value: "comments", label: "Comments" },
    { value: "mentions", label: "Mentions" },
    { value: "reactions", label: "Reactions" },
    { value: "sign-ins", label: "New sign-ins" },
    { value: "billing", label: "Billing" },
  ]
}

export { Example }
Choose Comments, then hold Shift and choose New sign-ins to select the range. A click replaces the selection; Ctrl or โŒ˜ adds one option.

Installation

npm install @ui-sdk/angular @ui-sdk/core

Composition

Use the following composition to build Listbox:

uiListbox
โ”œโ”€โ”€ uiListboxItem
โ”‚   โ””โ”€โ”€ uiListboxItemIndicator
โ””โ”€โ”€ uiListboxItem
    โ””โ”€โ”€ uiListboxItemIndicator

Give the list an accessible name and each option a unique value. uiListboxItemIndicator shows its content when that option is selected.

You can also name the list with a Field label or aria-labelledby. Keep buttons, search fields, and empty messages outside the list: its contents should be options, groups, and separators.

Usage

Import the parts and put them together:

import { Component } from "@angular/core"
import {
  Listbox,
  ListboxItem,
  ListboxItemIndicator,
} from "@ui-sdk/angular/listbox"

@Component({
  selector: "app-example",
  imports: [Listbox, ListboxItem, ListboxItemIndicator],
  template: `
    <div uiListbox aria-label="Toppings" defaultValue="basil">
      <div uiListboxItem value="basil">
        Basil
        <span *uiListboxItemIndicator>โœ“</span>
      </div>
      <div uiListboxItem value="olive">
        Olive
        <span *uiListboxItemIndicator>โœ“</span>
      </div>
    </div>
  `,
})
class Example {}

export { Example }

Multiple

Add multiple to select several options. The value becomes an array; a single list uses one value or null. By default, arrow keys move focus without changing a multiple selection.

ActionResult
Press an option or SpaceToggle that option.
Shift + press, arrow key, or SpaceSelect a range from the last chosen option.
Ctrl/Cmd + Shift + Home or EndExtend the range to the first or last option.
Ctrl/Cmd + ASelect every enabled option, then clear the selection.

Changing a Shift range preserves the options selected before that range began.

Console
import { Component } from "@angular/core"
import { LucideCheck } from "@lucide/angular"
import { useLog } from "./log"
import {
  Listbox,
  ListboxItem,
  ListboxItemIndicator,
} from "@ui-sdk/angular/listbox"

@Component({
  imports: [Listbox, ListboxItem, ListboxItemIndicator, LucideCheck],
  template: `
    <div
      uiListbox
      multiple
      [defaultValue]="['cheese', 'onion']"
      (beforeValueChange)="
        log(($event.value.join(', ') || 'Nothing') + ' (' + $event.reason + ')')
      "
      aria-label="Toppings"
    >
      @for (topping of toppings; track topping.value) {
        <div uiListboxItem [value]="topping.value">
          {{ topping.label }}
          <span *uiListboxItemIndicator>
            <svg lucideCheck></svg>
          </span>
        </div>
      }
    </div>
  `,
})
class Example {
  readonly toppings = [
    { value: "basil", label: "Basil" },
    { value: "cheese", label: "Extra cheese" },
    { value: "mushroom", label: "Mushroom" },
    { value: "olive", label: "Olive" },
    { value: "onion", label: "Onion" },
    { value: "pepper", label: "Pepper" },
  ]

  readonly log = useLog()
}

export { Example }
Choose Basil, then hold Shift and choose Pepper to select a range. Use Ctrl+A or โŒ˜A to select every option, then again to clear. The console logs each change.

Selection That Follows Focus

A single list selects as arrow keys, Page Up and Page Down, Home, End, or typing move focus. Page Up and Page Down move ten options, and stop at the ends. A multiple list can do the same with activation="automatic", like a file list: a press or arrow replaces the selection, Ctrl or Cmd adds to it, and Ctrl or Cmd with an arrow moves focus without selecting.

Taps and screen-reader presses toggle an option instead, since they do not have modifier keys.

<div uiListbox multiple activation="automatic" aria-label="Files"></div>
Console
import { Component } from "@angular/core"
import { LucideFile } from "@lucide/angular"
import { useLog } from "./log"
import { Listbox, ListboxItem, ListboxItemIcon } from "@ui-sdk/angular/listbox"

@Component({
  imports: [Listbox, ListboxItem, ListboxItemIcon, LucideFile],
  template: `
    <div
      uiListbox
      multiple
      activation="automatic"
      [defaultValue]="['readme']"
      (beforeValueChange)="
        log($event.value.length + ' selected (' + $event.reason + ')')
      "
      aria-label="Files"
    >
      @for (file of files; track file.value) {
        <div uiListboxItem [value]="file.value">
          <span uiListboxItemIcon>
            <svg lucideFile></svg>
          </span>
          {{ file.label }}
        </div>
      }
    </div>
  `,
})
class Example {
  readonly files = [
    { value: "readme", label: "README.md" },
    { value: "package", label: "package.json" },
    { value: "tsconfig", label: "tsconfig.json" },
    { value: "index", label: "index.ts" },
    { value: "styles", label: "styles.css" },
    { value: "logo", label: "logo.svg" },
  ]

  readonly log = useLog()
}

export { Example }
Choose index.ts to replace the selection. Hold Ctrl or Cmd while choosing another file to add it; Shift selects a range.

Manual Activation

Set activation="manual" on a single list to browse without selecting. Space, Enter, or a press chooses the focused option.

Console
import { Component } from "@angular/core"
import { LucideCheck } from "@lucide/angular"
import { useLog } from "./log"
import {
  Listbox,
  ListboxItem,
  ListboxItemIndicator,
} from "@ui-sdk/angular/listbox"

@Component({
  imports: [Listbox, ListboxItem, ListboxItemIndicator, LucideCheck],
  template: `
    <div
      uiListbox
      activation="manual"
      (beforeValueChange)="
        log(($event.value ?? 'Nothing') + ' (' + $event.reason + ')')
      "
      aria-label="Framework"
    >
      @for (framework of frameworks; track framework.value) {
        <div uiListboxItem [value]="framework.value">
          {{ framework.label }}
          <span *uiListboxItemIndicator>
            <svg lucideCheck></svg>
          </span>
        </div>
      }
    </div>
  `,
})
class Example {
  readonly frameworks = [
    { value: "next", label: "Next.js" },
    { value: "remix", label: "Remix" },
    { value: "astro", label: "Astro" },
    { value: "nuxt", label: "Nuxt" },
    { value: "sveltekit", label: "SvelteKit" },
  ]

  readonly log = useLog()
}

export { Example }
Move through the options with the arrow keys. Nothing is selected until you press Space or Enter, and the console logs the choice.

Focus on the List

Set virtualFocus to keep focus on the list itself while arrow keys, Home, End, and typing move a highlight through the options. The list points at the highlighted option with aria-activedescendant, so screen readers still announce it. Style the highlight with [data-highlighted], since the options don't take focus.

Console
import { Component } from "@angular/core"
import { LucideCheck } from "@lucide/angular"
import { useLog } from "./log"
import {
  Listbox,
  ListboxItem,
  ListboxItemIndicator,
} from "@ui-sdk/angular/listbox"

@Component({
  imports: [Listbox, ListboxItem, ListboxItemIndicator, LucideCheck],
  template: `
    <div
      uiListbox
      activation="manual"
      virtualFocus
      (beforeValueChange)="
        log(($event.value ?? 'Nothing') + ' (' + $event.reason + ')')
      "
      aria-label="Framework"
    >
      @for (framework of frameworks; track framework.value) {
        <div uiListboxItem [value]="framework.value">
          {{ framework.label }}
          <span *uiListboxItemIndicator>
            <svg lucideCheck></svg>
          </span>
        </div>
      }
    </div>
  `,
})
class Example {
  readonly frameworks = [
    { value: "next", label: "Next.js" },
    { value: "remix", label: "Remix" },
    { value: "astro", label: "Astro" },
    { value: "nuxt", label: "Nuxt" },
    { value: "sveltekit", label: "SvelteKit" },
  ]

  readonly log = useLog()
}

export { Example }
Tab into the list and move through it with the arrow keys. Focus stays on the list, and Space or Enter chooses the highlighted option.

Deselectable

Add deselectable to let pressing the selected option clear a single selection. Without it, the selection stays as it is.

Console
import { Component } from "@angular/core"
import { LucideCheck } from "@lucide/angular"
import { useLog } from "./log"
import {
  Listbox,
  ListboxItem,
  ListboxItemIndicator,
} from "@ui-sdk/angular/listbox"

@Component({
  imports: [Listbox, ListboxItem, ListboxItemIndicator, LucideCheck],
  template: `
    <div
      uiListbox
      deselectable
      defaultValue="astro"
      (beforeValueChange)="
        log(($event.value ?? 'Nothing') + ' (' + $event.reason + ')')
      "
      aria-label="Framework"
    >
      @for (framework of frameworks; track framework.value) {
        <div uiListboxItem [value]="framework.value">
          {{ framework.label }}
          <span *uiListboxItemIndicator>
            <svg lucideCheck></svg>
          </span>
        </div>
      }
    </div>
  `,
})
class Example {
  readonly frameworks = [
    { value: "next", label: "Next.js" },
    { value: "remix", label: "Remix" },
    { value: "astro", label: "Astro" },
    { value: "nuxt", label: "Nuxt" },
    { value: "sveltekit", label: "SvelteKit" },
  ]

  readonly log = useLog()
}

export { Example }
Press Astro again to clear the selection, or choose another framework. The console logs each change.

Groups

Use uiListboxGroup and uiListboxGroupLabel to name a group. Arrow keys and ranges continue across groups. Separators stay out of the accessibility tree.

import { Component } from "@angular/core"
import { LucideCheck } from "@lucide/angular"
import {
  Listbox,
  ListboxGroup,
  ListboxGroupLabel,
  ListboxItem,
  ListboxItemIndicator,
  ListboxSeparator,
} from "@ui-sdk/angular/listbox"

@Component({
  imports: [
    Listbox,
    ListboxGroup,
    ListboxGroupLabel,
    ListboxItem,
    ListboxItemIndicator,
    ListboxSeparator,
    LucideCheck,
  ],
  template: `
    <div uiListbox multiple [defaultValue]="['banana']" aria-label="Produce">
      @for (group of produce; track group.label; let index = $index) {
        @if (index > 0) {
          <div uiListboxSeparator></div>
        }
        <div uiListboxGroup>
          <div uiListboxGroupLabel>{{ group.label }}</div>
          @for (item of group.items; track item.value) {
            <div uiListboxItem [value]="item.value">
              {{ item.label }}
              <span *uiListboxItemIndicator>
                <svg lucideCheck></svg>
              </span>
            </div>
          }
        </div>
      }
    </div>
  `,
})
class Example {
  readonly produce = [
    {
      label: "Fruits",
      items: [
        { value: "apple", label: "Apple" },
        { value: "banana", label: "Banana" },
        { value: "orange", label: "Orange" },
      ],
    },
    {
      label: "Vegetables",
      items: [
        { value: "carrot", label: "Carrot" },
        { value: "broccoli", label: "Broccoli" },
        { value: "spinach", label: "Spinach" },
      ],
    },
  ]
}

export { Example }
Move from Apple through the list with Down Arrow. Navigation continues into the Vegetables group.

Icons

Wrap an icon in uiListboxItemIcon so screen readers and typeahead skip it. Add mirror to a directional icon to flip it in right-to-left text.

import { Component } from "@angular/core"
import {
  LucideArchive,
  LucideArrowRight,
  LucideDynamicIcon,
  LucideMail,
  LucidePencil,
  LucideStar,
} from "@lucide/angular"
import { Listbox, ListboxItem, ListboxItemIcon } from "@ui-sdk/angular/listbox"

@Component({
  imports: [Listbox, ListboxItem, ListboxItemIcon, LucideDynamicIcon],
  template: `
    <div uiListbox defaultValue="inbox" aria-label="Mailbox">
      @for (view of views; track view.value) {
        <div uiListboxItem [value]="view.value">
          <span uiListboxItemIcon [mirror]="view.icon === arrowRight">
            <svg [lucideIcon]="view.icon"></svg>
          </span>
          {{ view.label }}
        </div>
      }
    </div>
  `,
})
class Example {
  readonly views = [
    { value: "inbox", label: "Inbox", icon: LucideMail },
    { value: "starred", label: "Starred", icon: LucideStar },
    { value: "drafts", label: "Drafts", icon: LucidePencil },
    { value: "archive", label: "Archive", icon: LucideArchive },
    { value: "next", label: "Next page", icon: LucideArrowRight },
  ]

  readonly arrowRight = LucideArrowRight
}

export { Example }
Choose Drafts. The icon stays out of the optionโ€™s accessible name and the text used for typeahead.

Horizontal

Set orientation="horizontal" to move with Left and Right Arrow. Arrow keys normally wrap; set [loop]="false" to stop at the ends, as this example does. Shift ranges never wrap.

The list reads dir="rtl" from the page or an ancestor, so Left Arrow moves to the next option in right-to-left text.

import { Component } from "@angular/core"
import { Listbox, ListboxItem } from "@ui-sdk/angular/listbox"

@Component({
  imports: [Listbox, ListboxItem],
  template: `
    <div
      uiListbox
      orientation="horizontal"
      [loop]="false"
      defaultValue="m"
      aria-label="Size"
    >
      @for (size of sizes; track size.value) {
        <div uiListboxItem [value]="size.value" [disabled]="size.disabled">
          {{ size.label }}
        </div>
      }
    </div>
  `,
})
class Example {
  readonly sizes = [
    { value: "xs", label: "XS" },
    { value: "s", label: "S" },
    { value: "m", label: "M" },
    { value: "l", label: "L" },
    { value: "xl", label: "XL", disabled: true },
  ]
}

export { Example }
Focus M, then use Left and Right Arrow to choose a size. The list stops at its ends; XL cannot be selected.

Disabled

A disabled option cannot be selected. Arrow keys, typeahead and ranges skip it. Disabling the whole list removes its tab stop, prevents changes, and excludes its value from the form.

import { Component, signal } from "@angular/core"
import { LucideCheck } from "@lucide/angular"
import {
  Listbox,
  ListboxItem,
  ListboxItemIndicator,
} from "@ui-sdk/angular/listbox"

@Component({
  imports: [Listbox, ListboxItem, ListboxItemIndicator, LucideCheck],
  template: `
    <div data-slot="stack">
      <div data-slot="controls">
        <button type="button" (click)="disabled.set(!disabled())">
          {{ disabled() ? "Enable the List" : "Disable the List" }}
        </button>
      </div>
      <div
        uiListbox
        multiple
        [disabled]="disabled()"
        [defaultValue]="['basil']"
        aria-label="Toppings"
      >
        @for (topping of toppings; track topping.value) {
          <div
            uiListboxItem
            [value]="topping.value"
            [disabled]="topping.value === 'olive'"
          >
            {{ topping.label }}
            <span *uiListboxItemIndicator>
              <svg lucideCheck></svg>
            </span>
          </div>
        }
      </div>
    </div>
  `,
})
class Example {
  readonly toppings = [
    { value: "basil", label: "Basil" },
    { value: "cheese", label: "Extra cheese" },
    { value: "mushroom", label: "Mushroom" },
    { value: "olive", label: "Olive" },
    { value: "onion", label: "Onion" },
    { value: "pepper", label: "Pepper" },
  ]

  readonly disabled = signal(false)
}

export { Example }
Try choosing Olive. Then press Disable the List to make every option unavailable until you enable it again.

Read-Only

Use readOnly when people should be able to browse the list without changing its value. The list remains focusable and its value still submits.

import { Component } from "@angular/core"
import { LucideCheck } from "@lucide/angular"
import {
  Listbox,
  ListboxItem,
  ListboxItemIndicator,
} from "@ui-sdk/angular/listbox"

@Component({
  imports: [Listbox, ListboxItem, ListboxItemIndicator, LucideCheck],
  template: `
    <div uiListbox readOnly defaultValue="nuxt" aria-label="Framework">
      @for (framework of frameworks; track framework.value) {
        <div uiListboxItem [value]="framework.value">
          {{ framework.label }}
          <span *uiListboxItemIndicator>
            <svg lucideCheck></svg>
          </span>
        </div>
      }
    </div>
  `,
})
class Example {
  readonly frameworks = [
    { value: "next", label: "Next.js" },
    { value: "remix", label: "Remix" },
    { value: "astro", label: "Astro" },
    { value: "nuxt", label: "Nuxt" },
    { value: "sveltekit", label: "SvelteKit" },
  ]
}

export { Example }
Move focus through the frameworks. Nuxt stays selected because the list is read-only.

Form

Add name to submit the selection. Multiple selections submit one entry per value. Reset restores defaultValue, and required prevents submission when nothing is selected.

The server HTML includes the hidden inputs for the current selection, so those values can submit before hydration.

The list can live outside its form: set form to the formโ€™s ID, as this example does. A disabled fieldset also disables the list. Forms covers the shared integration.

Console
import { Component } from "@angular/core"
import { LucideCheck } from "@lucide/angular"
import { useLog } from "./log"
import {
  Listbox,
  ListboxItem,
  ListboxItemIndicator,
} from "@ui-sdk/angular/listbox"

@Component({
  imports: [Listbox, ListboxItem, ListboxItemIndicator, LucideCheck],
  template: `
    <div data-slot="stack">
      <div
        uiListbox
        multiple
        name="toppings"
        form="pizza-order"
        required
        [defaultValue]="['cheese']"
        aria-label="Toppings"
      >
        @for (topping of toppings; track topping.value) {
          <div uiListboxItem [value]="topping.value">
            {{ topping.label }}
            <span *uiListboxItemIndicator>
              <svg lucideCheck></svg>
            </span>
          </div>
        }
      </div>
      <form id="pizza-order" data-slot="row" (submit)="onSubmit($event)">
        <button type="reset">Reset</button>
        <button data-variant="solid">Order</button>
      </form>
    </div>
  `,
})
class Example {
  readonly toppings = [
    { value: "basil", label: "Basil" },
    { value: "cheese", label: "Extra cheese" },
    { value: "mushroom", label: "Mushroom" },
    { value: "olive", label: "Olive" },
    { value: "onion", label: "Onion" },
    { value: "pepper", label: "Pepper" },
  ]

  readonly log = useLog()

  onSubmit(event: SubmitEvent) {
    event.preventDefault()
    this.log(
      `Ordered ${new FormData(event.currentTarget as HTMLFormElement).getAll("toppings").join(", ")}`
    )
  }
}

export { Example }
Choose Basil and press Order: the console logs both toppings. Reset restores Extra cheese; clearing every option makes the required list block the order.

Object Values

Pass objects as item values when the selection should carry more than an ID. itemToValue provides the string used for identity and form submission; isItemEqualToValue matches objects that represent the same option but are different instances.

Console
import { Component } from "@angular/core"
import { LucideCheck } from "@lucide/angular"
import { useLog } from "./log"
import {
  Listbox,
  ListboxItem,
  ListboxItemIndicator,
  type ListData,
} from "@ui-sdk/angular/listbox"

@Component({
  imports: [Listbox, ListboxItem, ListboxItemIndicator, LucideCheck],
  template: `
    <div
      uiListbox
      [items]="plans"
      [defaultValue]="plans[1].value"
      (valueChange)="logPlan($event)"
      [itemToValue]="itemToValue"
      [isItemEqualToValue]="isItemEqualToValue"
      aria-label="Plan"
    >
      @for (plan of plans; track plan.value.id) {
        <div uiListboxItem [value]="plan.value" [disabled]="plan.disabled">
          {{ plan.label }}
          <span *uiListboxItemIndicator>
            <svg lucideCheck></svg>
          </span>
        </div>
      }
    </div>
  `,
})
class Example {
  readonly plans = [
    { value: { id: "hobby", price: 0 }, label: "Hobby" },
    { value: { id: "pro", price: 20 }, label: "Pro" },
    { value: { id: "team", price: 50 }, label: "Team" },
    {
      value: { id: "enterprise", price: 200 },
      label: "Enterprise",
      disabled: true,
    },
  ] satisfies ListData<{ id: string; price: number }>

  readonly log = useLog()

  readonly itemToValue = (plan: { id: string }) => plan.id

  readonly isItemEqualToValue = (
    plan: { id: string },
    selected: { id: string }
  ) => plan.id === selected.id

  logPlan(plan: { id: string; price: number } | null) {
    this.log(plan ? `${plan.id}, $${plan.price} a month` : "No plan")
  }
}

export { Example }
Choose Team. The console logs the price from the selected object, not from its string ID.

items supplies the collection as data, and uiListboxItems inside the listbox renders the options for you. To keep markup and classes explicit, map the data into parts, as the example does. Use ListData<T> to type object-valued data. Lists and Menus covers the shared data format.

Controller

A controller can select all options, clear the selection, or focus the list from another control. Create one with createListboxController() and pass it as controller. Controllers covers setup and lifetime.

Console
import { Component } from "@angular/core"
import { LucideCheck } from "@lucide/angular"
import { useLog } from "./log"
import {
  createListboxController,
  Listbox,
  ListboxItem,
  ListboxItemIndicator,
} from "@ui-sdk/angular/listbox"

@Component({
  imports: [Listbox, ListboxItem, ListboxItemIndicator, LucideCheck],
  template: `
    <div data-slot="stack">
      <div data-slot="controls">
        <button type="button" (click)="controller.selectAll()">
          Select All
        </button>
        <button type="button" (click)="controller.clear()">Clear</button>
        <button type="button" (click)="controller.focus()">Focus</button>
      </div>
      <div
        uiListbox
        multiple
        [controller]="controller"
        (beforeValueChange)="
          log($event.value.length + ' selected (' + $event.reason + ')')
        "
        aria-label="Toppings"
      >
        @for (topping of toppings; track topping.value) {
          <div uiListboxItem [value]="topping.value">
            {{ topping.label }}
            <span *uiListboxItemIndicator>
              <svg lucideCheck></svg>
            </span>
          </div>
        }
      </div>
    </div>
  `,
})
class Example {
  readonly toppings = [
    { value: "basil", label: "Basil" },
    { value: "cheese", label: "Extra cheese" },
    { value: "mushroom", label: "Mushroom" },
    { value: "olive", label: "Olive" },
    { value: "onion", label: "Onion" },
    { value: "pepper", label: "Pepper" },
  ]

  readonly log = useLog()

  readonly controller = createListboxController<string, true>()
}

export { Example }
Press Select All, Clear and Focus. Each button drives the same list through its controller, and the console logs the change.

Scrollable

Give a long list a maximum height and overflow-y: auto. It starts scrolled to the selected option without taking focus. Keyboard navigation reveals the focused option without scrolling the page.

Console
import { Component } from "@angular/core"
import { LucideCheck } from "@lucide/angular"
import { useLog } from "./log"
import {
  Listbox,
  ListboxItem,
  ListboxItemIndicator,
  type ListboxHighlight,
} from "@ui-sdk/angular/listbox"

@Component({
  imports: [Listbox, ListboxItem, ListboxItemIndicator, LucideCheck],
  template: `
    <div
      uiListbox
      defaultValue="utc9"
      (highlight)="onHighlight($event)"
      aria-label="Time zone"
    >
      @for (zone of timezones; track zone.value; let index = $index) {
        <div uiListboxItem [value]="zone.value" [index]="index">
          {{ zone.label }}
          <span *uiListboxItemIndicator>
            <svg lucideCheck></svg>
          </span>
        </div>
      }
    </div>
  `,
})
class Example {
  readonly timezones = Array.from({ length: 27 }, (_, index) => {
    const offset = index - 12
    const label = `UTC${offset < 0 ? "โˆ’" : "+"}${String(Math.abs(offset)).padStart(2, "0")}:00`
    return { value: `utc${offset}`, label }
  })

  readonly log = useLog()

  onHighlight(highlight: ListboxHighlight) {
    if (highlight.value) {
      this.log(
        `Focused ${this.timezones[highlight.index].label} (${highlight.index + 1} of ${this.timezones.length})`
      )
    }
  }
}

export { Example }
Focus the list and use the arrow keys. Options scroll into view, and the console logs the focused time zone.

For a virtualized list, supply items so typeahead knows about unmounted options. (highlight) reports the focused value and index; each rendered itemโ€™s index places it in the full collection for screen readers. The Select virtualization example shows the same data and scrolling approach.

Set [keepInView]="false" when something else scrolls the list, like a wheel that picks the option at its center with bindScrollPicker. The list then leaves its scroll position alone as keys move focus.

Custom Rendering

Render an option as a link when choosing it should navigate. A press or Enter follows the link and selects the option. This example uses manual activation so arrow keys only browse.

<a uiListboxItem value="remix" href="#remix">Remix</a>
import { Component } from "@angular/core"
import { LucideExternalLink } from "@lucide/angular"
import { Listbox, ListboxItem } from "@ui-sdk/angular/listbox"

@Component({
  imports: [Listbox, ListboxItem, LucideExternalLink],
  template: `
    <div
      uiListbox
      defaultValue="next"
      activation="manual"
      aria-label="Framework docs"
    >
      @for (framework of frameworks; track framework.value) {
        <a
          uiListboxItem
          #item="uiListboxItem"
          [value]="framework.value"
          [label]="framework.label"
          [href]="'#' + framework.value"
        >
          <span>{{ framework.label }}</span>
          @if (item.state().selected) {
            <svg lucideExternalLink></svg>
          }
        </a>
      }
    </div>
  `,
})
class Example {
  readonly frameworks = [
    { value: "next", label: "Next.js" },
    { value: "remix", label: "Remix" },
    { value: "astro", label: "Astro" },
    { value: "nuxt", label: "Nuxt" },
    { value: "sveltekit", label: "SvelteKit" },
  ]
}

export { Example }
Focus Remix and press Enter, or choose it with the pointer. The option is selected and its link updates the URL hash.

Parts and Composition covers the shared rendering API. Each partโ€™s state is listed below.

Styling

Use data-selected for the selection and data-highlighted for focus. They can describe different options when selection does not follow focus. Disabled and read-only states have their own attributes.

Each part has a data-slot, such as listbox-item, and its state attributes are listed under Data Attributes.

Data Attributes

uiListboxGroup, uiListboxGroupLabel and uiListboxSeparator have no state attributes.

Listbox

[data-slot="listbox"]

AttributeWhat it means
data-orientationverticalhorizontalWhich arrow keys move between items.
data-disabledPresent when the listbox is disabled, by its own prop, a Field or a <fieldset>.
data-readonlyPresent when the listbox is read-only.
data-requiredPresent when the listbox is required.
data-has-iconsPresent while any item inside holds an icon part, so items without one can line up.

ListboxItem

[data-slot="listbox-item"]

AttributeWhat it means
data-selectedPresent on selected items, and on the check inside them.
data-disabledPresent when the item can't be chosen. It can still be focused.
data-highlightedPresent on the item that has focus.
data-has-iconPresent on an item while it holds an icon part.

ListboxItemIndicator

[data-slot="listbox-item-indicator"]

AttributeWhat it means
data-selectedPresent on selected items, and on the check inside them.

ListboxItemIcon

[data-slot="listbox-item-icon"]

AttributeWhat it means
data-mirrorPresent on an icon that flips in right-to-left text, with mirror.

API Reference

Each option below is an input on the directive, and each callback an output. A change callback is two outputs: (beforeValueChange), with the details and cancel(), then (valueChange) with the new value alone. Bind value with [(value)].

Listbox

activation?"automatic" | "manual"
Whether the selection follows focus. "automatic": arrow keys, Home, End and typing select the option they move to, and with multiple a press replaces the selection while Ctrl or โŒ˜ adds to it, like a native multiple select. "manual": keys only move focus, and Space, Enter or a press selects, or toggles with multiple.
deselectable?boolean
Whether pressing the selected item of a single listbox unselects it, so nothing is selected.
orientation?"horizontal" | "vertical"
Which arrow keys move between items. Horizontal lists use Left and Right, swapped in right-to-left text.
loop?boolean
Whether arrow keys wrap from the last item to the first. Shift with an arrow never wraps.
virtualFocus?boolean
Keeps focus on the list itself, which points at the highlighted option with aria-activedescendant, instead of moving focus onto the options.
keepInView?boolean
Whether the list scrolls the option keys move to into view, and the selected option when it first shows. Turn it off when something else scrolls the list, like bindScrollPicker.
items?ListData<T>
The items as data. Renders them for you, and lets typing find items a virtualized list hasn't rendered.
itemToValue?((value: T) => string)
The string an item's value submits as and is identified by, for object values. Strings pass through, and objects use their value or id.
isItemEqualToValue?((itemValue: T, value: T) => boolean)
Whether an item's value is the selected value, for object values that aren't the same object.
(highlight)
Runs when focus moves to another item, with its index among the items, so a virtualized list can scroll to it.
disabled?boolean
Disables the listbox like a native control: its items can't be focused or chosen, and the value isn't submitted.
readOnly?boolean
Keeps the listbox focusable and its value submitted, but stops changes.
required?boolean
Blocks form submission until a value is selected, with the browser's own message.
name?string
The name the value submits under. Without one, the listbox submits nothing.
form?string
The id of a form to belong to, when the listbox isn't inside that form.
controller?object
Reads and sets the listbox from anywhere. Create one with createListboxController().
debug?boolean
Logs every state change with its reason to the console, in development builds.
multiple?boolean
Whether several items can be selected. The value is then a list, Shift selects ranges, and Ctrl or โŒ˜ with A selects every item. Whether several items can be selected.
value?T | T[] | null
The selected value. Pass it to control the listbox. null selects nothing. The selected values. Pass it to control the listbox. The selected value, or values with multiple. Pass it to control the listbox.
defaultValue?T | T[] | null
The value selected at first, when uncontrolled. A form reset returns to it. The values selected at first, when uncontrolled. A form reset returns to them. The value or values selected at first, when uncontrolled. A form reset returns to it.
(beforeValueChange)
Runs when a user, a form reset or a controller wants to change the value. details.reason says why, and details.cancel() stops it.

ListboxItem

valueT
What the value becomes when the item is chosen. A string, or any value with itemToValue.
label?string
The text typing finds, when the content isn't plain text. Not the accessible name: use aria-label for that.
disabled?boolean
Keeps the item from being chosen. Arrow keys, typing and ranges skip it. Sets data-disabled and aria-disabled.
index?number
The item's position among all items, for virtualized lists that render only some. Sets aria-posinset and aria-setsize.

ListboxItemIndicator

keepMounted?boolean
Whether the indicator stays in the page while its item isn't selected, so it can be styled or animated in both states.

ListboxItemIcon

mirror?boolean
Flips the icon horizontally in right-to-left text, for icons that point a way, like arrows and chevrons. Icons that picture a thing, like a clock or a check, stay as they are.

uiListboxGroup, uiListboxGroupLabel and uiListboxSeparator take no inputs of their own.

State

What each part's state() signal holds, per part.

uiListbox:

multipleboolean | undefined
Whether several items can be selected.
orientation"horizontal" | "vertical"
Which arrow keys move between items.
disabledboolean
Whether the listbox is disabled, by itself, a Field or a <fieldset>.
readOnlyboolean
Whether the listbox keeps its value but refuses changes, from its readOnly option. A form reset still restores it.
requiredboolean
Whether a value is required.
itemsListData<unknown>
The data items, for rendering a virtualized list yourself. Empty without items.

uiListboxItem:

highlightedboolean
Whether the item has focus.
selectedboolean
Whether its value is in the listbox's value, compared with isItemEqualToValue when you pass one.
disabledboolean
Whether the item can't be chosen, by itself or a disabled listbox.

uiListboxItemIndicator:

selectedboolean
Whether its item is selected. While false, the indicator isn't shown unless keepMounted is set.

Reasons

$event.reason says why the value changed: item-press for a press, Space or Enter, list-navigation for keys that select as they move, Shift ranges with arrows and Ctrl or โŒ˜ with A, reset and restore from the form, and imperative from a controller.

item-pressMouseEvent | KeyboardEvent
A member of a collection was chosen: a menu item, a tab, a radio or a checkbox item.
list-navigationKeyboardEvent
Arrow, Home or End keys moved the selection, typing picked an item, or Ctrl or โŒ˜ with A selected every item of a listbox.
resetnone
A form reset.
restorenone
The browser restored state, like after going back, or a saved value was read back from storage.
imperativenone
A controller or api call.

Controller

Create one with createListboxController() and pass it as controller.

Every write method takes an optional { reason, event }, passed to (beforeValueChange).

getValue()() => ListboxValue<T, Multiple>
The selected value.
setValue(value, options?)(value: ListboxValue<T, Multiple>, options?: ListboxChangeOptions | undefined) => boolean
Selects a value, as a user would. A disabled or read-only listbox ignores it. Returns false when the change was canceled or nothing changed.
clear(options?)(options?: ListboxChangeOptions | undefined) => boolean
Selects nothing: null, or an empty list with multiple. Returns false when the change was canceled or nothing changed.
selectAll(options?)(options?: ListboxChangeOptions | undefined) => boolean
Selects every enabled item, with multiple. Returns false when the change was canceled or nothing changed.
getHighlighted()() => T | null
The value of the highlighted option, or null when none is, like while focus is outside the list.
highlight(value)(value: T | null) => boolean
Highlights the option with this value, scrolled into view, or none with null. While focus is outside the list, the option takes the tab stop instead, so focus lands on it next. Returns false when no enabled option has the value.
focus()() => void
Moves focus into the list, onto the option that holds its tab stop.

Events

A before output emits { value, reason, event, cancel() } before the change, and its plain output follows with the value alone. A bound value only updates when (beforeValueChange) wasn't canceled.

BindingOnReceives
[(value)]uiListboxThe selected value
(beforeValueChange)uiListbox{ value, reason, cancel() }: the new value, and the reason
(highlight)uiListbox{ value, reason, cancel() }: the focused option's value, and its index

Accessibility

Follows the WAI-ARIA listbox pattern, with both of its keyboard models for several options. Options take real focus with one roving tab stop. Every option says whether it's selected.

Focus

The list is one tab stop. Tab returns to the last focused option, then falls back to the first selected or enabled option. Options receive real DOM focus, so focus-visible works directly. With virtualFocus, the list is the tab stop and keeps focus instead.

The root forwards focus into the options, including when you press a Field label or the listโ€™s padding. Escape stays available to an enclosing dialog.

Tested Behavior

Every line below is an automated test.

Focus
  • Tab lands on the first option when nothing is selected.
  • Tab lands on the selected option.
  • Tab lands on the first selected option with multiple.
  • The list is one tab stop: Tab leaves it from any option.
  • Shift+Tab back into the list returns to the option focused last.
  • A press focuses the option.
  • Arrow keys skip disabled options.
  • A disabled option can't be chosen.
  • Arrow keys from a pressed disabled option move to the enabled ones around it.
  • Tab lands on the first enabled option when the selected one is disabled.
Single selection
  • Arrow keys move focus and the selection follows.
  • Home and End move to the first and last option.
  • Arrow keys wrap from the last option to the first.
  • With loop off, arrow keys stop at the ends.
  • A press selects the option.
  • Pressing the selected option keeps it selected.
  • With deselectable, pressing the selected option unselects it.
  • With manual activation, arrows only move focus and Space selects.
  • Typing moves focus to the next option that starts with it, and selects it.
  • Typing several letters finds the option that starts with them.
  • Escape leaves the selection alone.
Multiple selection
  • Presses and Space toggle options.
  • Arrow keys move focus without changing the selection.
  • Shift with a press selects the range from the last option chosen.
  • Shift with an arrow passes over a disabled option.
  • A range skips disabled options.
  • A second Shift press changes the range, keeping what was selected before it.
  • Shift with an arrow key moves focus and extends the selection.
  • Shift with Space selects from the last option chosen to the focused one.
  • Ctrl+Shift+End selects from the focused option to the last.
  • Ctrl+Shift+Home selects from the focused option to the first.
  • Ctrl+A selects every enabled option, and again unselects them.
  • Ctrl+A does nothing in a single listbox.
  • Typing moves focus without selecting.
Multiple selection with automatic activation
  • A press replaces the selection.
  • Ctrl or Cmd with a press adds an option, and removes it again.
  • Shift with a press replaces the selection with a range.
  • Arrow keys select the option they move to.
  • Ctrl or Cmd with an arrow moves focus only, and with Space toggles.
  • Shift with an arrow key extends the selection.
Horizontal
  • Left and Right move between options, and Up and Down don't.
Groups
  • Arrow keys move across groups, skipping their labels.
  • A range crosses groups.
Form
  • Submits the selected value under its name.
  • Submits each value with multiple.
  • A reset returns to the default value.
  • Required blocks submission until a value is selected.
  • A disabled listbox can't be focused or changed, and submits nothing.
  • A disabled fieldset disables the listbox.
  • A read-only listbox can be browsed but not changed, and submits.
Changes
  • A canceled change keeps the selection.
  • A controlled listbox shows the value it's given.
  • The controller clears and selects everything.

Runs in React, Vue and web components.

Beyond the pattern:

  • Keys pressed with no waits between them all land.
  • Escape leaves the selection alone and reaches a dialog around the list.
  • A Shift press after the selection was cleared starts a new range there.
  • Shift with an arrow never wraps past the end.
  • A Shift press doesn't select the page's text.
  • The selected option scrolls into view without taking focus.
  • Arrow keys keep the focused option clear of the list's scroll padding at both ends.
  • The selected option scrolls into view clear of the list's scroll padding.
  • A focused option that leaves the list hands focus back to it, so keys keep working.
  • Options that all leave take the tab stop with them, and options that come back hold it again.
  • Options the app reorders keep their place in the keys.
  • A press on the list's padding gives focus to the option that holds the tab stop.
Touch
  • Taps toggle where clicks replace, since touch has no modifier keys.
Focus on the list
  • With virtualFocus, keys move the highlight while focus stays on the list, which points at it.
  • With virtualFocus, a press chooses an option and keeps focus on the list.

Runs in React, Vue and web components.

Screen readers hear the same thing in each tested framework, recorded by a virtual screen reader:

  • Announcements while choosing one option with a keyboard.
  • Announcements while choosing several options with a keyboard.

Runs in React, Vue and web components.