Skip to content
Cynosurev0.5.0
SearchStorybookGitHubnpmColour mode: System. Switch to Light

Components / More

OptionList

The drop-down list of options under a field: options with an optional icon and description, group headings, and a note when there is nothing to choose. Select, Combobox and TagInput draw their lists with it. It is a building block: for a ready field, use one of those.

Groups are named by their headings

When to useLink to "When to use"

  • Building a new field whose choices drop down under it, so its list looks and behaves like Select's and Combobox's.

Use something else when:

  • people pick one value from a list: Select
  • people type to filter suggestions: Combobox
  • the list is a set of actions, not values: Menu

UsageLink to "Usage"

tsx
Copy
import { OptionList, OptionListItem, OptionListNote } from "@arshad-shah/cynosure";

useListboxLayer({ anchor: field, list, open, onClose: () => setOpen(false) });

<OptionList ref={list} id={listId} label="Fruit">
  {matches.length === 0 && <OptionListNote>No matches</OptionListNote>}
  {matches.map((fruit, index) => (
    <OptionListItem
      key={fruit.value}
      id={`${listId}-${index}`}
      label={fruit.label}
      description={fruit.description}
      selected={fruit.value === value}
      active={index === active}
      disabled={fruit.disabled}
      onPointerMove={() => setActive(index)}
      onClick={() => choose(fruit)}
    />
  ))}
</OptionList>

The list is a manual popover. useListboxLayer (in src/overlay/listbox-layer.ts) shows it in the top layer, at least as wide as the field and below it, and closes it on Escape or a press outside.

Options, descriptions and notesLink to "Options, descriptions and notes"

OptionListItem takes a label, an optional description (a smaller, muted second line) and an icon drawn before the text. selected marks the chosen option, active highlights the one the arrow keys are on, and disabled fades an option and marks it aria-disabled. OptionListNote stands in for options when nothing matches or results are loading.

Disabled options descriptions and notes

trailing puts a shortcut or a count at the end of an option's row, smaller and muted. dimmed draws an option muted while it stays choosable: a saved connection that is not connected, say. footer pins an action under the options, set off by a line and kept in view while the options scroll: "Manage connections…".

The footer is an option, not a separate button. The field keeps focus and points at options with aria-activedescendant, and a listbox may only hold options, so a button would be out of reach of the arrow keys and a Tab to it would close the list. As an option it is the last stop of the arrow keys, Enter runs it and a press runs it without moving focus. The list draws it from footer={{ action, id, active, onActive, onRun }}; the field that owns the list decides what choosing it does: Select and Combobox take a footer action ({ label, icon?, onSelect }), make it the last stop of useActiveOption, and close the list before running it.

Trailing dimmed and footer

PropsLink to "Props"

Every prop of OptionList
PropWhat it doesTypeDefault
idRequired
The list's id: the field's aria-controls, and the prefix of the options' ids.string
label
Accessible name, when no visible label names the list through aria-labelledby.string
aria-labelledby
The id of the visible label that names the list.string
busy
Options are still loading (aria-busy).boolean
className
Added to the root element, for layout.string
style
Layout only. Restyle through --cy-option-list-* tokens.CSSProperties
children
OptionListItem, OptionListNote and OptionListGroup.ReactNode
footer
An action pinned under the options, set off by a line and kept in view while they scroll ("Manage connections…"). The list draws it as an option (a listbox holds only options), so the field's arrow keys reach it after the last option and Enter runs it, while focus stays in the field. Select's and Combobox's footer.OptionListFooter

Generated from the type definitions in @arshad-shah/cynosure 0.5.0.

Behaviour and accessibilityLink to "Behaviour and accessibility"

  • Roles: the list is a listbox named by label or aria-labelledby; options are options with aria-selected; groups are groups named by their heading.
  • Focus: a press on an option never moves focus: the field keeps it and points at the active option with aria-activedescendant.
  • Keys: the list handles none; the field that owns it does (arrows, Enter, Escape, type-ahead).
  • Loading: busy sets aria-busy.
  • Footer: an option in a role="none" wrapper at the end of the listbox, after every option and group.
  • Right to left: the icon leads on the right, and trailing content ends the row on the left.

TouchLink to "Touch"

Options are at least 44px tall on coarse pointers, and a tap chooses.

ThemingLink to "Theming"

Tokens: --cy-option-list-bg, --cy-option-list-shadow, --cy-option-list-max-height, --cy-option-list-max-width and --cy-option-list-active-bg. Select and Combobox set them from their own list tokens (--cy-select-list-bg, --cy-combobox-list-bg and the rest).

Tokens restyle the list

Select · Combobox · TagInput · Menu

These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.

Getting started
Theming
Icons
Accessibility
Code editors and highlighters
Using Cynosure without React
Build-tool adapters
Components
Accordion
AppShell
AspectRatio
Breadcrumbs
Calendar
Card
Container
Disclosure
Divider
DocumentViewport
Grid
Inline
PageHeader
PanZoomCanvas
ScrollArea
SideNav
SortableList
SplitPane
Stack
StatusBar
Tabs
TitleBar
Toolbar
Tree
VirtualList
ZoomControls
Announcer
Avatar
Badge
CodeBlock
DescriptionList
EmptyState
ErrorBoundary
Field
Heading
IconTile
Image
Kbd
List
LoadingDots
Notice
ProgressBar
Prose
Skeleton
Stat
Steps
Table
Text
Button
Checkbox
Checklist
ColorField
ColorSwatches
Combobox
CompareSlider
CopyButton
DateField
FileDrop
IconButton
KeyValueEditor
Link
NumberField
Pagination
PathField
RadioGroup
SearchField
SegmentedControl
Select
SelectionFrame
SignaturePad
Slider
Switch
TagInput
TextArea
TextField
ThemeToggle
TimeField
ButtonBase
ChoiceBase
DialogBase
FileInputBase
HiddenValue
Icon
InputBase
LinkBase
LiveRegion
TextAreaBase
ChatMessage
Choice
DataGrid
DeviceFrame
HighlightedText
HotkeyField
ListRow
OptionList
OverlayFrame
QRCode
RowActions
Section
SiteFooter
SiteHeader
SkipLink
SortButton
VisuallyHidden
CommandPalette
ContextMenu
Dialog
FloatingToolbar
HoverCard
Menu
Menubar
Popover
ProgressOverlay
Sheet
Toast
Tooltip
Changelog