SearchCtrlK

  • ↑↓navigate
  • ↵open
  • escclose

Can’t find it? Contact us

ListBox

A run of selectable option rows sharing one native grouping name.

Move issue to
Active
Archived

Arrow keys move the active row, Enter selects it, and typing jumps to a match.

View code
tsx
let value = "docs-site";
let activeValue: listbox.ListboxValue = "docs-site";

<listbox.Context
	value={value}
	activeValue={activeValue}
	onSelect={(next) => {
		value = next ?? value;
		void handle.update();
	}}
	onHighlight={(next) => {
		activeValue = next;
		void handle.update();
	}}
>
	<div mix={[vstack({ gap: 2, align: "stretch" })]}>
		<Header mix={[m(0)]}>Move issue to</Header>

		<ListBox
			role="listbox"
			tabIndex={0}
			aria-label="Move issue to"
			name="projectId"
			mix={[listboxKeys()]}
		>
			{GROUPS.map((group) => (
				<Section key={group.id} aria-labelledby={group.id + "-heading"}>
					<Header id={group.id + "-heading"}>{group.label}</Header>
					{group.options.map((option) => (
						<ListBox.Item
							key={option.value}
							value={option.value}
							checked={value === option.value}
							disabled={option.disabled}
							mix={[listbox.option({ value: option.value, label: option.label, disabled: option.disabled })]}
						>
							{option.label}
						</ListBox.Item>
					))}
				</Section>
			))}
		</ListBox>

		<p mix={[m(0), text("xs")]}>
			Arrow keys move the active row, Enter selects it, and typing jumps to a match.
		</p>
	</div>
</listbox.Context>

Installation

An ordinary dependency: install it, import the theme once, and import the component where it is used.

Terminal
npm add @sdxc/ui remix
typescript
import "@sdxc/ui/theme.css";

Or copy it into your project to edit it:

Terminal
sdxc ui add listbox

Usage

typescript
import { ListBox } from "@sdxc/ui";

Renders the group host: a <div> laying its ListBox.Item options out as a scrollable column capped at a fixed block size and rounded concentric with its rows, with role defaulting to "radiogroup" for single selection or "group" for multiple.

Composition

The parts the component publishes, each a static property of the host.

  • ListBox
  • ListBox.ItemRenders a single option: a native <label> pairing a visually hidden radio or checkbox input with the option's content.

Examples

Several choices, grouped

Channels
View code
tsx
<ListBox aria-label="Notifications" multiple>
	<Section aria-labelledby="channels-heading">
		<Header id="channels-heading">Channels</Header>
		<ListBox.Item value="email" defaultChecked>Email</ListBox.Item>
		<ListBox.Item value="sms">SMS</ListBox.Item>
		<ListBox.Item value="push" defaultChecked>Push notifications</ListBox.Item>
	</Section>
</ListBox>

Props

Read from the component's own types, so every prop, every default and every allowed value is listed.

PropTypeDefaultRequiredDescription
namestring—NoNative grouping name shared by every ListBox.Item nested inside, provided through component context. Defaults to the group's own stable instance id, so options always group correctly.
multipleboolean—NoRenders every option as a checkbox, allowing more than one selected at once, instead of the default mutually exclusive radio behavior. Defaults to DEFAULT_MULTIPLE.

Also accepts everything in TagProps<"div">.

ListBox.Item

PropTypeDefaultRequiredDescription
valuestring—YesValue submitted with the enclosing form when this option is selected.
namestring—NoNative grouping name for this option's underlying input. Defaults to the name provided by the nearest ancestor ListBox — set this only to opt a single option out of its group's shared name.
defaultCheckedboolean—NoWhether this option starts selected, for a form that never tracks selection itself.
checkedboolean—NoWhether this option is selected, for a form that tracks selection itself.
disabledboolean—NoWhether this option is inert and excluded from the group's tab order.
requiredboolean—NoSets the underlying input's native required attribute. On a radio input this requires at least one option in the group be selected; on a checkbox input it requires this specific option be checked.
childrenRemixNode—NoThe option's visible content, associated with the input by native nesting.

Also accepts everything in Omit<TagProps<"label">, "children">.

@sdxc/ui

Can’t find it? Contact us