Listbox is a flat list the user picks one row from. It is the core Listbox with a
simpler selection:
With value and onValueChange, the user picks one row.
Without them, the list is only for display.
Listbox.Root takes one value where the core root takes an array, and Listbox.Item takes an option’s id where
the core item takes the option. The other parts are the core parts.
Use this Listbox when the user picks at most one row. Use the core one when the user selects several rows.
Each part handles keyboard navigation and the current and selected states. Each part also sets its own spacing, so put
the list in a panel’s body with no padding around it.
Each option has a value, a label and an optional description. Inside each Listbox.Item, the parts read the
option, so Listbox.ItemText shows the option’s label without being told.
Example (Picking a person)
1
import {
functionuseState<S>(initialState: S | (() =>S)): [S, React.Dispatch<React.SetStateAction<S>>] (+1overload)
Returns a stateful value, and a function to update it.
Selectable or plain list on Next parts, with Listbox's part names. Wrap Content in a Viewport for a list that
scrolls itself; leave it bare inside a host that scrolls (such as a ScrollArea composed in Panel.Body). The
current ItemContent becomes a row composed from ItemIcon, ItemText,
ItemDescription and trailing controls. Annotated so the declaration names Next's parts through Next rather than
react-ui's modules.
Listbox } from'@dxos/react-ui-list';
3
4
/** One row per option; selecting a row reports its value. */
5
exportconst
constPeopleListbox: () =>React.JSX.Element
One row per option; selecting a row reports its value.
Selectable or plain list on Next parts, with Listbox's part names. Wrap Content in a Viewport for a list that
scrolls itself; leave it bare inside a host that scrolls (such as a ScrollArea composed in Panel.Body). The
current ItemContent becomes a row composed from ItemIcon, ItemText,
ItemDescription and trailing controls. Annotated so the declaration names Next's parts through Next rather than
react-ui's modules.
Selected option id (controlled). Supplying any of value/defaultValue/onValueChange makes the list
single-selection; omitting all three selects nothing (selectionMode='none'), keeping zag's navigation. Multiple
selection, or a useListSelection-shaped value, goes through listboxSelection on Listbox.Root.
Selectable or plain list on Next parts, with Listbox's part names. Wrap Content in a Viewport for a list that
scrolls itself; leave it bare inside a host that scrolls (such as a ScrollArea composed in Panel.Body). The
current ItemContent becomes a row composed from ItemIcon, ItemText,
ItemDescription and trailing controls. Annotated so the declaration names Next's parts through Next rather than
react-ui's modules.
Selectable or plain list on Next parts, with Listbox's part names. Wrap Content in a Viewport for a list that
scrolls itself; leave it bare inside a host that scrolls (such as a ScrollArea composed in Panel.Body). The
current ItemContent becomes a row composed from ItemIcon, ItemText,
ItemDescription and trailing controls. Annotated so the declaration names Next's parts through Next rather than
react-ui's modules.
Selectable or plain list on Next parts, with Listbox's part names. Wrap Content in a Viewport for a list that
scrolls itself; leave it bare inside a host that scrolls (such as a ScrollArea composed in Panel.Body). The
current ItemContent becomes a row composed from ItemIcon, ItemText,
ItemDescription and trailing controls. Annotated so the declaration names Next's parts through Next rather than
react-ui's modules.
Selectable or plain list on Next parts, with Listbox's part names. Wrap Content in a Viewport for a list that
scrolls itself; leave it bare inside a host that scrolls (such as a ScrollArea composed in Panel.Body). The
current ItemContent becomes a row composed from ItemIcon, ItemText,
ItemDescription and trailing controls. Annotated so the declaration names Next's parts through Next rather than
react-ui's modules.
Calls a defined callback function on each element of an array, and returns an array that contains the results.
@param ― callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
@param ― thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
Selectable or plain list on Next parts, with Listbox's part names. Wrap Content in a Viewport for a list that
scrolls itself; leave it bare inside a host that scrolls (such as a ScrollArea composed in Panel.Body). The
current ItemContent becomes a row composed from ItemIcon, ItemText,
ItemDescription and trailing controls. Annotated so the declaration names Next's parts through Next rather than
react-ui's modules.
Selectable or plain list on Next parts, with Listbox's part names. Wrap Content in a Viewport for a list that
scrolls itself; leave it bare inside a host that scrolls (such as a ScrollArea composed in Panel.Body). The
current ItemContent becomes a row composed from ItemIcon, ItemText,
ItemDescription and trailing controls. Annotated so the declaration names Next's parts through Next rather than
react-ui's modules.
Selectable or plain list on Next parts, with Listbox's part names. Wrap Content in a Viewport for a list that
scrolls itself; leave it bare inside a host that scrolls (such as a ScrollArea composed in Panel.Body). The
current ItemContent becomes a row composed from ItemIcon, ItemText,
ItemDescription and trailing controls. Annotated so the declaration names Next's parts through Next rather than
react-ui's modules.
Selectable or plain list on Next parts, with Listbox's part names. Wrap Content in a Viewport for a list that
scrolls itself; leave it bare inside a host that scrolls (such as a ScrollArea composed in Panel.Body). The
current ItemContent becomes a row composed from ItemIcon, ItemText,
ItemDescription and trailing controls. Annotated so the declaration names Next's parts through Next rather than
react-ui's modules.
Selectable or plain list on Next parts, with Listbox's part names. Wrap Content in a Viewport for a list that
scrolls itself; leave it bare inside a host that scrolls (such as a ScrollArea composed in Panel.Body). The
current ItemContent becomes a row composed from ItemIcon, ItemText,
ItemDescription and trailing controls. Annotated so the declaration names Next's parts through Next rather than
react-ui's modules.
Selectable or plain list on Next parts, with Listbox's part names. Wrap Content in a Viewport for a list that
scrolls itself; leave it bare inside a host that scrolls (such as a ScrollArea composed in Panel.Body). The
current ItemContent becomes a row composed from ItemIcon, ItemText,
ItemDescription and trailing controls. Annotated so the declaration names Next's parts through Next rather than
react-ui's modules.
Selectable or plain list on Next parts, with Listbox's part names. Wrap Content in a Viewport for a list that
scrolls itself; leave it bare inside a host that scrolls (such as a ScrollArea composed in Panel.Body). The
current ItemContent becomes a row composed from ItemIcon, ItemText,
ItemDescription and trailing controls. Annotated so the declaration names Next's parts through Next rather than
react-ui's modules.
Selectable or plain list on Next parts, with Listbox's part names. Wrap Content in a Viewport for a list that
scrolls itself; leave it bare inside a host that scrolls (such as a ScrollArea composed in Panel.Body). The
current ItemContent becomes a row composed from ItemIcon, ItemText,
ItemDescription and trailing controls. Annotated so the declaration names Next's parts through Next rather than
react-ui's modules.
Selectable or plain list on Next parts, with Listbox's part names. Wrap Content in a Viewport for a list that
scrolls itself; leave it bare inside a host that scrolls (such as a ScrollArea composed in Panel.Body). The
current ItemContent becomes a row composed from ItemIcon, ItemText,
ItemDescription and trailing controls. Annotated so the declaration names Next's parts through Next rather than
react-ui's modules.
Listbox.Item gets only the option’s value, as its id. Listbox.ItemText and Listbox.ItemDescription take no
props, and onValueChange keeps the picked value in state.