SelectBoxGroup allows users to select one or more options from a list.
Content
SelectBoxGroup follows the Collection Components API, accepting both static and dynamic collections. This example shows a dynamic collection, passing a list of objects to the items prop, and a function to render the children.
import {SelectBoxGroup, SelectBox, Text} from '@react-spectrum/s2/SelectBoxGroup';
import {style} from '@react-spectrum/s2/style' with {type: 'macro'};
import Home from '@react-spectrum/s2/illustrations/linear/Home';
import Phone from '@react-spectrum/s2/illustrations/linear/Phone';
import MailOpen from '@react-spectrum/s2/illustrations/linear/MailOpen';
let options = [
{ id: 'address', name: 'Home address', illustration: <Home /> },
{ id: 'email', name: 'Email address', illustration: <MailOpen /> },
{ id: 'phone', name: 'Phone number', illustration: <Phone /> }
];
function Example() {
return (
<SelectBoxGroup
aria-label="Contact info"
items={options}
selectionMode="multiple"
styles={style({width: 'full'})}>
{((item) => (
<SelectBox id={item.id} textValue={item.name}>
{item.illustration}
<Text slot="label">{item.name}</Text>
</SelectBox>
))}
</SelectBoxGroup>
);
}
Selection
Use the selectionMode prop to enable single or multiple selection. The selected items can be controlled via the selectedKeys prop, matching the id prop of the items. Items can be disabled with the isDisabled prop. See the selection guide for more details.
Current selection:
API
<SelectBoxGroup>
<SelectBox>
<Illustration />
<Text slot="label" />
<Text slot="description" />
</SelectBox>
</SelectBoxGroup>
SelectBoxGroup
| Name | Type | Default |
|---|---|---|
orientation | Orientation | Default: 'vertical'
|
The layout direction of the content in each SelectBox. | ||
isDisabled | boolean | Default: — |
Whether the SelectBoxGroup is disabled. | ||
styles | StylesProp | Default: — |
Spectrum-defined styles, returned by the | ||
children | ReactNode | | Default: — |
The SelectBox elements contained within the SelectBoxGroup. | ||
items | Iterable | Default: — |
Item objects in the collection. | ||
selectionMode | 'single' | 'multiple' | Default: 'single'
|
The selection mode for the SelectBoxGroup. | ||
selectedKeys | 'all' | Iterable | Default: — |
The currently selected keys in the collection (controlled). | ||
defaultSelectedKeys | 'all' | Iterable | Default: — |
The initial selected keys in the collection (uncontrolled). | ||
onSelectionChange | | Default: — |
Handler that is called when the selection changes. | ||
disabledKeys | Iterable | Default: — |
The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with. | ||
disallowEmptySelection | boolean | Default: — |
Whether the collection allows empty selection. | ||
escapeKeyBehavior | 'clearSelection' | 'none' | Default: 'clearSelection'
|
Whether pressing the escape key should clear selection in the listbox or not. Most experiences should not modify this option as it eliminates a keyboard user's ability to easily clear selection. Only use if the escape key is being handled externally or should not trigger selection clearing contextually. | ||
onFocus | | Default: — |
Handler that is called when the element receives focus. | ||
onBlur | | Default: — |
Handler that is called when the element loses focus. | ||
onFocusChange | | Default: — |
Handler that is called when the element's focus status changes. | ||
autoFocus | boolean | FocusStrategy | Default: — |
Whether to auto focus the listbox or an option. | ||
id | string | Default: — |
The element's unique identifier. See MDN. | ||
aria-label | string | Default: — |
Defines a string value that labels the current element. | ||
aria-labelledby | string | Default: — |
Identifies the element (or elements) that labels the current element. | ||
aria-describedby | string | Default: — |
Identifies the element (or elements) that describes the object. | ||
aria-details | string | Default: — |
Identifies the element (or elements) that provide a detailed, extended description for the object. | ||
UNSAFE_className | UnsafeClassName | Default: — |
Sets the CSS className
for the element. Only use as a last resort. Use the | ||
UNSAFE_style | CSSProperties | Default: — |
Sets inline style for the
element. Only use as a last resort. Use the | ||
slot | string | null | Default: — |
A slot name for the component. Slots allow the component to receive props from a parent
component. An explicit | ||
SelectBox
| Name | Type | |
|---|---|---|
id | Key | |
The unique id of the SelectBox. | ||
textValue | string | |
A string representation of the SelectBox's contents, used for features like typeahead. | ||
children | ReactNode | |
The contents of the SelectBox. | ||
isDisabled | boolean | |
Whether the SelectBox is disabled. | ||
styles | StylesProp | |
Spectrum-defined styles, returned by the | ||
aria-label | string | |
An accessibility label for this item. | ||
UNSAFE_className | UnsafeClassName | |
Sets the CSS className
for the element. Only use as a last resort. Use the | ||
UNSAFE_style | CSSProperties | |
Sets inline style for the
element. Only use as a last resort. Use the | ||