ListBox

Listbox shows lists

installyarn add @react-spectrum/listbox
version3.0.0-alpha.1
usageimport {ListBox} from '@react-spectrum/listbox'

Example#


<ListBox width={200} aria-label="label">
  <Section title="Justify">
    <Item>Left</Item>
    <Item>Middle</Item>
    <Item>Right</Item>
  </Section>
  <Section title="Align">
    <Item>Top</Item>
    <Item>Center</Item>
    <Item>Bottom</Item>
  </Section>
</ListBox>

Content#


Accessibility#

Internationalization#

Events#


Props#


NameTypeDefaultDescription
autoFocusboolean | FocusStrategy—
shouldFocusWrapboolean—
childrenReactElement<SectionProps<T>> | ReactElement<ItemProps<T>> | ReactElement<SectionProps<T>> | ReactElement<ItemProps<T>>[] | (item: T) => ReactElement<SectionProps<T>> | ReactElement<ItemProps<T>>—The contents of the collection.
disabledKeysIterable<Key>—They item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with.
itemsIterable<T>—Item objects in the collection or section.
itemKeystring—Property name on each item object to use as the unique key. id or key by default.
isLoadingboolean—Whether the items are currently loading.
selectionModeSelectionMode—The type of selection that is allowed in the collection.
disallowEmptySelectionboolean—Whether the collection allows empty selection.
selectedKeys'all' | Iterable<Key>—The currently selected keys in the collection (controlled).
defaultSelectedKeys'all' | Iterable<Key>—The initial selected keys in the collection (uncontrolled).
UNSAFE_classNamestring—
UNSAFE_styleCSSProperties—
Events
NameTypeDefaultDescription
onLoadMore() => any—Handler that is called when more items should be loaded, e.g. while scrolling near the bottom.
onSelectionChange(keys: Selection) => any—Handler that is called when the selection changes.
Layout
NameTypeDefaultDescription
flexstring | number | boolean—
flexGrownumber—
flexShrinknumber—
flexBasisnumber | string—
alignSelf'auto' | 'normal' | 'start' | 'end' | 'flex-start' | 'flex-end' | 'self-start' | 'self-end' | 'center' | 'stretch'—
justifySelf'auto' | 'normal' | 'start' | 'end' | 'flex-start' | 'flex-end' | 'self-start' | 'self-end' | 'center' | 'left' | 'right' | 'stretch'—
flexOrdernumber—
gridAreastring—
gridColumnstring—
gridRowstring—
gridColumnStartstring—
gridColumnEndstring—
gridRowStartstring—
gridRowEndstring—
Spacing
NameTypeDefaultDescription
marginDimensionValue—
marginTopDimensionValue—
marginLeftDimensionValue—
marginRightDimensionValue—
marginBottomDimensionValue—
marginStartDimensionValue—
marginEndDimensionValue—
marginXDimensionValue—
marginYDimensionValue—
Sizing
NameTypeDefaultDescription
widthDimensionValue—
minWidthDimensionValue—
maxWidthDimensionValue—
heightDimensionValue—
minHeightDimensionValue—
maxHeightDimensionValue—
Positioning
NameTypeDefaultDescription
position'static' | 'relative' | 'absolute' | 'fixed' | 'sticky'—
topDimensionValue—
bottomDimensionValue—
leftDimensionValue—
rightDimensionValue—
startDimensionValue—
endDimensionValue—
zIndexnumber—
isHiddenboolean—
Accessibility
NameTypeDefaultDescription
rolestring—
idstring—
tabIndexnumber—
aria-labelstring—Defines a string value that labels the current element.
aria-labelledbystring—Identifies the element (or elements) that labels the current element.
aria-describedbystring—Identifies the element (or elements) that describes the object.
aria-controlsstring—Identifies the element (or elements) whose contents or presence are controlled by the current element.
aria-ownsstring—Identifies an element (or elements) in order to define a visual, functional, or contextual parent/child relationship between DOM elements where the DOM hierarchy cannot be used to represent the relationship.
aria-hiddenboolean | 'false' | 'true'—Indicates that the element is perceivable but disabled, so it is not editable or otherwise operable.

Visual options#