PeakUI

ListBox

A listbox displays selectable options

Usage

import { ListBox } from "@peakui/react";

Anatomy

import { Description, Label, ListBox } from "@peakui/react";

export default () => (
  <ListBox>
    <ListBox.Item textValue="Option">
      <Label />
      <Description />
      <ListBox.ItemIndicator />
    </ListBox.Item>
    <ListBox.Section>
      <ListBox.Item textValue="Grouped option">
        <Label />
      </ListBox.Item>
    </ListBox.Section>
  </ListBox>
);

Examples

With Sections

With Disabled Items

Multi Select

Controlled

Custom Check Icon

Render Function

Customization

Tailwind CSS

Global CSS

@layer components {
  .list-box {
    @apply rounded-lg border border-border bg-surface p-2;
  }

  .list-box-item {
    @apply rounded px-2 py-1 cursor-pointer;
  }

  .list-box-item--danger {
    @apply text-danger;
  }

  .list-box-item__indicator {
    @apply text-accent;
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The ListBox component uses these CSS classes (view source styles):

Base Classes

  • .list-box - Base listbox container
  • .list-box-item - Individual listbox item
  • .list-box-item__indicator - Selection indicator icon
  • .list-box-section - Section container for grouping items

Variant Classes

  • .list-box--default - Default variant
  • .list-box--danger - Danger variant
  • .list-box-item--default - Default item variant
  • .list-box-item--danger - Danger item variant

Slots

  • [data-slot="list-box"] - The listbox root
  • [data-slot="list-box-item"] - A listbox item
  • [data-slot="list-box-item-indicator"] - The selection indicator
  • [data-slot="list-box-item-indicator--checkmark"] - The default checkmark glyph
  • [data-slot="list-box-section"] - A section

Interactive States

The component supports both CSS pseudo-classes and data attributes:

  • Hover: :hover or [data-hovered="true"] on item
  • Focus: :focus-visible or [data-focus-visible="true"] on item
  • Pressed: :active or [data-pressed="true"] on item
  • Selected: [aria-selected="true"] or [data-selected="true"] on item
  • Disabled: [data-disabled="true"] on item
  • Indicator visible: [data-visible="true"] on the indicator

API Reference

ListBox

PropTypeDefaultDescription
aria-labelstring-Accessibility label for the listbox
aria-labelledbystring-ID of element that labels the listbox
selectionMode"none" | "single" | "multiple""single"Selection behavior
selectedKeysSelection-Controlled selected keys
defaultSelectedKeysSelection-Initial selected keys
onSelectionChange(keys: Selection) => void-Handler called when selection changes
disabledKeysIterable<Key>-Keys of disabled items
onAction(key: Key) => void-Handler called when an item is activated
variant"default" | "danger""default"Visual variant
classNamestring-Additional CSS classes
childrenReactNode-ListBox items and sections
renderDOMRenderFunction<keyof React.JSX.IntrinsicElements, ListBoxRenderProps>-Overrides the default DOM element with a custom render function

ListBox.Item

PropTypeDefaultDescription
idKey-Unique identifier for the item
textValuestring-Text value for accessibility and typeahead
isDisabledbooleanfalseWhether this item is disabled
variant"default" | "danger""default"Visual variant
classNamestring-Additional CSS classes
childrenReactNode | ((renderProps: ListBoxItemRenderProps) => ReactNode)-Item content or render function
render(props, renderProps: ListBoxItemRenderProps) => ReactElement-Overrides the default DOM element with a custom render function

ListBox.ItemIndicator

PropTypeDefaultDescription
classNamestring-Additional CSS classes
childrenReactNode | ((renderProps: ListBoxItemRenderProps) => ReactNode)-Custom indicator content or render function

ListBox.Section

PropTypeDefaultDescription
aria-labelstring-Accessibility label for the group
classNamestring-Additional CSS classes
childrenReactNode-Section content: a heading, then items

Render Props

When using render functions with ListBox.Item or ListBox.ItemIndicator, these values are provided:

PropTypeDescription
isSelectedbooleanWhether the item is selected
isFocusedbooleanWhether the item is focused
isDisabledbooleanWhether the item is disabled
isPressedbooleanWhether the item is being pressed

On this page