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>
<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>
<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
autoFocusbooleanFocusStrategyWhether the auto focus the listbox or an option.
shouldFocusWrapbooleanWhether focus should wrap around when the end/start is reached.
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.
isLoadingbooleanWhether the items are currently loading.
selectionModeSelectionModeThe type of selection that is allowed in the collection.
disallowEmptySelectionbooleanWhether 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( ( )) => anyHandler that is called when more items should be loaded, e.g. while scrolling near the bottom.
onSelectionChange( (keys: Selection )) => anyHandler that is called when the selection changes.
Layout
NameTypeDefaultDescription
flexstringnumberboolean
flexGrownumber
flexShrinknumber
flexBasisnumberstring
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
idstring
aria-labelstringDefines a string value that labels the current element.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.
aria-describedbystringIdentifies the element (or elements) that describes the object.
aria-detailsstringIdentifies the element (or elements) that provide a detailed, extended description for the object.

Visual options#