Skip to Content
CodeUI

Listbox

@codeui/solid v0.3.0

An inline collection with single or multiple selection.

When to use

Use Listbox when you need visible options that select one or more values, such as export formats or snippet languages.

When to choose another component

Use Select for a collapsed picker. Use Combobox when you need a search field. Use VirtualizedListbox for a long collection.

Live demo

  • TypeScript
  • Rust
  • Python
listbox/basic.tsx
import { Listbox } from "@codeui/solid";
export default function Basic() {
	return <Listbox aria-label="Snippet language" options={["TypeScript", "Rust", "Python"]} selectionMode="single" defaultValue={["TypeScript"]} disallowEmptySelection size="sm" />;
}

disallowEmptySelection keeps a language selected. Values are collections of option keys even in single selection mode.

Anatomy

  • TypeScript
  • Rust
  • Python

Tap a part to outline it in the demo.

  1. 01Listboxlistboxclasses.root
  2. 02ListboxItemlistbox-itemclasses.item
  3. 03Item labellistbox-item-labelclasses.itemLabel
  4. 04Item indicatorlistbox-item-indicatorclasses.itemIndicator
ExportRendersclasses keydata-cuiRole
Listboxulrootlistboxlistbox
ListboxItemliitemlistbox-itemoption
Internal labeldivitemLabellistbox-item-labelLabel text
Internal indicatordivitemIndicatorlistbox-item-indicatorSelection check

The ready Listbox renders ListboxItem for each option. The indicator stays mounted to reserve space.

Variants

Selection modes

  • PNG
  • SVG
  • WebP

Selected formats: PNG

  • PNG
  • SVG
  • WebP
listbox/selection.tsx
import { Listbox } from "@codeui/solid";
import { createSignal } from "solid-js";
export default function Selection() {
	const [selected, setSelected] = createSignal(new Set(["PNG"]));
	return <div>
		<Listbox aria-label="Export formats" options={["PNG", "SVG", "WebP"]} selectionMode="multiple" value={selected()} onChange={setSelected} size="sm" />
		<p>Selected formats: {Array.from(selected()).join(", ") || "None"}</p>
		<Listbox aria-label="Available formats, selection off" options={["PNG", "SVG", "WebP"]} selectionMode="none" size="sm" />
	</div>;
}

single selects one key. multiple selects several keys. none allows navigation without selection. The controlled value and onChange use a Set<string>. Set selectionBehavior="replace" for desktop range selection behavior.

Sizes

xs

  • TypeScript
  • Rust

sm

  • TypeScript
  • Rust

md

  • TypeScript
  • Rust
listbox/sizes.tsx
import { Listbox } from "@codeui/solid";
import { For } from "solid-js";
export default function Sizes() {
	return <For each={["xs", "sm", "md"] as const}>{size => <div><p>{size}</p><Listbox aria-label={`${size} languages`} options={["TypeScript", "Rust"]} selectionMode="single" size={size} /></div>}</For>;
}

Rows use the shared sm height (32px compact, 36px comfortable, 40px touch). The size prop controls row typography and shape. Use sm for the Inkstone desktop control height.

States

  • Fetch with retries
  • Archived parser
listbox/customization.tsx
import { Listbox } from "@codeui/solid";
const snippets = [{ id: "fetch", title: "Fetch with retries", disabled: false }, { id: "old", title: "Archived parser", disabled: true }];
export default function Customization() {
	return <Listbox aria-label="Saved snippets" options={snippets} optionValue="id" optionTextValue="title" optionDisabled="disabled" itemLabel={snippet => snippet.title} selectionMode="single" class="snippet-list" classes={{ item: "snippet-option", itemLabel: "snippet-label", itemIndicator: "snippet-check" }} size="sm" />;
}

Object options need optionValue and optionTextValue. optionDisabled marks unavailable options. itemLabel renders the object as readable content. class targets the root. classes targets the four parts in the anatomy table.

    No saved snippets.

    listbox/empty.tsx
    import { Listbox } from "@codeui/solid";
    export default function Empty() {
    	return <div><Listbox<string> aria-label="Saved snippets" options={[]} selectionMode="single" /><p>No saved snippets.</p></div>;
    }

    An empty collection renders an empty list. Render an empty message beside it.

    Ready API

    Listbox

    Renders the list and its options.

    Prop

    Type

    Prop

    Type

    ListboxItem

    Renders a Kobalte collection node with a label and check indicator. The ready list normally creates it for you.

    Prop

    Type

    Prop

    Type

    ListboxClasses contains the four optional class names in the anatomy table. The remaining collection and keyboard props follow the Kobalte Listbox contract.

    Styled parts API

    Use @codeui/solid/listbox/parts to control option markup. Pass options and renderItem to Root. The callback receives a collection node. Pass it to Item to keep selection and keyboard navigation. Use ItemLabel, ItemDescription, and ItemIndicator to compose the row. Use Section for grouped options.

    Accessibility

    Keyboard

    KeyAction
    TabEnters the list at the selected or first enabled option, then leaves the list.
    Up Arrow, Down ArrowMoves focus between enabled options.
    Home, EndMoves to the first or last enabled option.
    Enter, SpaceSelects the focused option according to the selection mode.
    CharactersMoves focus to the next matching text value.
    Shift + ArrowExtends a multiple selection when the selection behavior supports ranges.

    ARIA

    The root has role="listbox". Items have role="option", aria-selected, and aria-disabled when applicable. Multiple selection adds aria-multiselectable. Supply aria-label or aria-labelledby for the list. optionTextValue provides the plain text used for typeahead when labels contain custom markup.

    Focus

    Options take DOM focus. Hover focuses options by default. Disabled options are skipped. The list stays inline, so there is no open or close cycle and no focus restoration target.

    SSR notes

    The list and its options render inline on the server. Keep option keys and initial selection stable between server render and hydration. There is no portal.

    Theming hooks

    The list reads --cui-surface-menu, --cui-surface-menu-hover, --cui-text-menu, --cui-text-selected, and --cui-accent-selection. Geometry uses --cui-radius-xs, --cui-radius-sm, --cui-radius-lg, --cui-control-height-md, and --cui-space-1, --cui-space-2, --cui-space-3. Text uses --cui-font-size-sm, --cui-font-size-md, and --cui-font-weight-normal. The legacy bordered mode reads --cui-border-width, --cui-border-divider, and --cui-focus-color. The styles also reference --cui-shadow-menu and --cui-border-menu. Keep the neutral variant and borderless default for Inkstone. The primary highlight and bordered mode are legacy styles.

    Composition examples

    Sections

    • Web
    • TypeScript
    • CSS
    • Systems
    • Rust
    • Go
    listbox/sections.tsx
    import { Listbox } from "@codeui/solid";
    const groups = [
    	{ label: "Web", languages: ["TypeScript", "CSS"] },
    	{ label: "Systems", languages: ["Rust", "Go"] },
    ];
    export default function Sections() {
    	return <Listbox<string, typeof groups[number]> aria-label="Language by category" options={groups} optionGroupChildren="languages" selectionMode="single" size="sm" renderSection={section => <li role="presentation">{section.rawValue.label}</li>} />;
    }

    optionGroupChildren identifies each group's options. renderSection renders a nonselectable heading before those options. The section heading is not an option and arrow navigation skips it. The parts entry point exports Section for custom listboxes.

    On this page