Floating List
Provides the ability to create composable children APIs for list components
This is useful to prevent the need to keep track of a list item’s
index for useListNavigation
or
useTypeahead
.
Manually specifying an index poses problems when wrapper tags surround list items, such as with grouping.
An example of a composable children API looks like the following,
where <Select>
does not receive an array prop but rather
children:
Examples
Usage
FloatingList
This component is a context provider that receives two props:
- elementsRef —
useListNavigation()
’slistRef
prop (array of elements). - labelsRef —
useTypeahead()
’slistRef
prop (array of strings; optional).
useListItem()
This Hook is used to register a list item and its index (DOM
position) in the FloatingList
. It returns two properties:
ref and index.
The Hook optionally accepts a label
prop, which is used to
determine the string that can be matched with typeahead:
The label
can be null
for disabled items, which will be
ignored for typeahead.