Picker
Pickers allow users to choose a single option from a collapsible list of options when space is limited.
install | yarn add @react-spectrum/picker |
---|---|
version | 3.0.0-alpha.1 |
usage | import {Picker, Item, Section} from '@react-spectrum/picker' |
Example#
<Picker
label="Choose frequency"
onSelectionChange=(selected) => consolelog(selected)>
<Item key="rarely">Rarely</Item>
<Item key="sometimes">Sometimes</Item>
<Item key="always">Always</Item>
</Picker>
<Picker
label="Choose frequency"
onSelectionChange=(selected) => consolelog(selected)>
<Item key="rarely">Rarely</Item>
<Item key="sometimes">Sometimes</Item>
<Item key="always">Always</Item>
</Picker>
<Picker
label="Choose frequency"
onSelectionChange=(
selected
) =>
consolelog(
selected
)
>
<Item key="rarely">
Rarely
</Item>
<Item key="sometimes">
Sometimes
</Item>
<Item key="always">
Always
</Item>
</Picker>
Content#
Picker follows the Collection Components API, accepting both static and dynamic forms of children. Similar to the Menu, Picker accepts an <Item>
component, each with a key
prop. Basic usage of the Picker, seen in the example above, shows multiple options populated with a string. This implementation would be used when the list of options is finite and known.
The dynamic method (shown below) would be better suited to use if the options came from a data object such as values returned from an API call. Providing the data in this way allows for Picker to automatically cache the rendering of each item, which dramatically improves performance.
As seen below, an iterable list of options is passed to the Picker using the items
prop. Each item accepts a key prop, which is passed to the onSelectionChange handler to identify the selected item. Alternatively, if the item objects contain an id property, as shown in the example below, then this is used automatically and a key prop is not required. See the events section for more detail on selection.
function Example() {
let options = [
{id: 1 name: 'Aardvark'}
{id: 2 name: 'Cat'}
{id: 3 name: 'Dog'}
{id: 4 name: 'Kangaroo'}
{id: 5 name: 'Koala'}
{id: 6 name: 'Penguin'}
{id: 7 name: 'Snake'}
{id: 8 name: 'Turtle'}
{id: 9 name: 'Wombat'}
];
return (
// Dynamic Items
<Picker
label="Pick an animal"
items= options
onSelectionChange=(selected) => consolelog(selected)>
(item) => <Item> itemname</Item>
</Picker>
);
}
function Example() {
let options = [
{id: 1 name: 'Aardvark'}
{id: 2 name: 'Cat'}
{id: 3 name: 'Dog'}
{id: 4 name: 'Kangaroo'}
{id: 5 name: 'Koala'}
{id: 6 name: 'Penguin'}
{id: 7 name: 'Snake'}
{id: 8 name: 'Turtle'}
{id: 9 name: 'Wombat'}
];
return (
// Dynamic Items
<Picker
label="Pick an animal"
items= options
onSelectionChange=(selected) =>
consolelog(selected)
>
(item) => <Item> itemname</Item>
</Picker>
);
}
function Example() {
let options = [
{
id: 1
name: 'Aardvark'
}
{id: 2 name: 'Cat'}
{id: 3 name: 'Dog'}
{
id: 4
name: 'Kangaroo'
}
{
id: 5
name: 'Koala'
}
{
id: 6
name: 'Penguin'
}
{
id: 7
name: 'Snake'
}
{
id: 8
name: 'Turtle'
}
{
id: 9
name: 'Wombat'
}
];
return (
// Dynamic Items
<Picker
label="Pick an animal"
items= options
onSelectionChange=(
selected
) =>
consolelog(
selected
)
>
(item) => (
<Item>
itemname
</Item>
)
</Picker>
);
}
Internationalization#
To internationalize a Picker, a localized string should be passed to the children
of each Item
.
For languages that are read right-to-left (e.g. Hebrew and Arabic), the layout of the Picker is flipped.
Labeling#
Picker can be labeled using the label
prop. If no label is provided, an alternative text label must be provided to identify the control for accessibility. This should be added using the aria-label
prop. If the Picker is a required field, the isRequired
and necessityIndicator
props can be used to show a required state.
<Picker label="Choose frequency" isRequired necessityIndicator="icon">
<Item key="rarely">Rarely</Item>
<Item key="sometimes">Sometimes</Item>
<Item key="always">Always</Item>
</Picker>
<Picker
label="Choose frequency"
isRequired
necessityIndicator="icon">
<Item key="rarely">Rarely</Item>
<Item key="sometimes">Sometimes</Item>
<Item key="always">Always</Item>
</Picker>
<Picker
label="Choose frequency"
isRequired
necessityIndicator="icon">
<Item key="rarely">
Rarely
</Item>
<Item key="sometimes">
Sometimes
</Item>
<Item key="always">
Always
</Item>
</Picker>
<Picker label="Choose frequency" isRequired necessityIndicator="label">
<Item key="rarely">Rarely</Item>
<Item key="sometimes">Sometimes</Item>
<Item key="always">Always</Item>
</Picker>
<Picker
label="Choose frequency"
isRequired
necessityIndicator="label">
<Item key="rarely">Rarely</Item>
<Item key="sometimes">Sometimes</Item>
<Item key="always">Always</Item>
</Picker>
<Picker
label="Choose frequency"
isRequired
necessityIndicator="label">
<Item key="rarely">
Rarely
</Item>
<Item key="sometimes">
Sometimes
</Item>
<Item key="always">
Always
</Item>
</Picker>
<Picker label="Choose frequency" necessityIndicator="label">
<Item key="rarely">Rarely</Item>
<Item key="sometimes">Sometimes</Item>
<Item key="always">Always</Item>
</Picker>
<Picker label="Choose frequency" necessityIndicator="label">
<Item key="rarely">Rarely</Item>
<Item key="sometimes">Sometimes</Item>
<Item key="always">Always</Item>
</Picker>
<Picker
label="Choose frequency"
necessityIndicator="label">
<Item key="rarely">
Rarely
</Item>
<Item key="sometimes">
Sometimes
</Item>
<Item key="always">
Always
</Item>
</Picker>
Selection#
Setting a selected option can be done by using the defaultSelectedKey
or selectedKey
prop. The selected key corresponds to the key
of an item. See Events for more details on selection events.
function Example() {
let options = [
{name: 'Koala'}
{name: 'Kangaroo'}
{name: 'Platypus'}
{name: 'Bald Eagle'}
{name: 'Bison'}
{name: 'Skunk'}
];
let [animal setAnimal] = ReactuseState("Bison");
return (
<>
<Picker
label="Pick an animal (uncontrolled)"
items= options
defaultSelectedKey="Bison"
marginEnd="size-300">
item => <Item key= itemname> itemname</Item>
</Picker>
<Picker
label="Pick an animal (controlled)"
items= options
selectedKey= animal
onSelectionChange= selected => setAnimal(selected)>
item => <Item key= itemname> itemname</Item>
</Picker>
</>
);
}
function Example() {
let options = [
{name: 'Koala'}
{name: 'Kangaroo'}
{name: 'Platypus'}
{name: 'Bald Eagle'}
{name: 'Bison'}
{name: 'Skunk'}
];
let [animal setAnimal] = ReactuseState("Bison");
return (
<>
<Picker
label="Pick an animal (uncontrolled)"
items= options
defaultSelectedKey="Bison"
marginEnd="size-300">
item => <Item key= itemname> itemname</Item>
</Picker>
<Picker
label="Pick an animal (controlled)"
items= options
selectedKey= animal
onSelectionChange= selected => setAnimal(selected)>
item => <Item key= itemname> itemname</Item>
</Picker>
</>
);
}
function Example() {
let options = [
{name: 'Koala'}
{name: 'Kangaroo'}
{name: 'Platypus'}
{name: 'Bald Eagle'}
{name: 'Bison'}
{name: 'Skunk'}
];
let [
animal
setAnimal
] = ReactuseState(
'Bison'
);
return (
<>
<Picker
label="Pick an animal (uncontrolled)"
items= options
defaultSelectedKey="Bison"
marginEnd="size-300">
(item) => (
<Item
key=
itemname
>
itemname
</Item>
)
</Picker>
<Picker
label="Pick an animal (controlled)"
items= options
selectedKey=
animal
onSelectionChange=(
selected
) =>
setAnimal(
selected
)
>
(item) => (
<Item
key=
itemname
>
itemname
</Item>
)
</Picker>
</>
);
}
Sections#
Picker supports sections in order to group options. Sections can be used by wrapping groups of Items in a Section
component. Each Section
takes a title
and key
prop.
Static items#
<Picker label="Pick your favorite">
<Section title="Animals">
<Item key="Aardvark">Aardvark</Item>
<Item key="Kangaroo">Kangaroo</Item>
<Item key="Snake">Snake</Item>
</Section>
<Section title="People">
<Item key="Danni">Danni</Item>
<Item key="Devon">Devon</Item>
<Item key="Ross">Ross</Item>
</Section>
</Picker>
<Picker label="Pick your favorite">
<Section title="Animals">
<Item key="Aardvark">Aardvark</Item>
<Item key="Kangaroo">Kangaroo</Item>
<Item key="Snake">Snake</Item>
</Section>
<Section title="People">
<Item key="Danni">Danni</Item>
<Item key="Devon">Devon</Item>
<Item key="Ross">Ross</Item>
</Section>
</Picker>
<Picker label="Pick your favorite">
<Section title="Animals">
<Item key="Aardvark">
Aardvark
</Item>
<Item key="Kangaroo">
Kangaroo
</Item>
<Item key="Snake">
Snake
</Item>
</Section>
<Section title="People">
<Item key="Danni">
Danni
</Item>
<Item key="Devon">
Devon
</Item>
<Item key="Ross">
Ross
</Item>
</Section>
</Picker>
Dynamic items#
Sections used with dynamic items are populated from a hierarchical data structure. Similarly to the props on Picker
, Section
takes an array of data using the items
prop.
function Example() {
let options = [
{
name: 'Australian'
children: [
{id: 2 name: 'Koala'}
{id: 3 name: 'Kangaroo'}
{id: 4 name: 'Platypus'}
]
}
{
name: 'American'
children: [
{id: 6 name: 'Bald Eagle'}
{id: 7 name: 'Bison'}
{id: 8 name: 'Skunk'}
]
}
];
return (
<>
<Picker
label="Pick an animal"
items= options
onSelectionChange=(selected) => alert(selected)>
(item) => (
<Section key= itemname items= itemchildren title= itemname>
(item) => <Item> itemname</Item>
</Section>
)
</Picker>
</>
);
}
function Example() {
let options = [
{
name: 'Australian'
children: [
{id: 2 name: 'Koala'}
{id: 3 name: 'Kangaroo'}
{id: 4 name: 'Platypus'}
]
}
{
name: 'American'
children: [
{id: 6 name: 'Bald Eagle'}
{id: 7 name: 'Bison'}
{id: 8 name: 'Skunk'}
]
}
];
return (
<>
<Picker
label="Pick an animal"
items= options
onSelectionChange=(selected) => alert(selected)>
(item) => (
<Section
key= itemname
items= itemchildren
title= itemname>
(item) => <Item> itemname</Item>
</Section>
)
</Picker>
</>
);
}
function Example() {
let options = [
{
name: 'Australian'
children: [
{
id: 2
name: 'Koala'
}
{
id: 3
name:
'Kangaroo'
}
{
id: 4
name:
'Platypus'
}
]
}
{
name: 'American'
children: [
{
id: 6
name:
'Bald Eagle'
}
{
id: 7
name: 'Bison'
}
{
id: 8
name: 'Skunk'
}
]
}
];
return (
<>
<Picker
label="Pick an animal"
items= options
onSelectionChange=(
selected
) =>
alert(selected)
>
(item) => (
<Section
key=
itemname
items=
itemchildren
title=
itemname
>
(item) => (
<Item>
itemname
</Item>
)
</Section>
)
</Picker>
</>
);
}
Events#
Picker supports selection via mouse, keyboard, and touch. You can handle all of these via the onSelectionChange
prop. Picker will pass the selected key
to the onSelectionChange
handler.
The following example uses an onSelectionChange
handler to update the selection stored in React state.
function StaticExample() {
let [frequency setFrequency] = ReactuseState();
return (
<>
<Picker
label="Choose frequency"
onSelectionChange=(selected) => setFrequency(selected)>
<Item key="Rarely">Rarely</Item>
<Item key="Sometimes">Sometimes</Item>
<Item key="Always">Always</Item>
</Picker>
<p>You selected frequency</p>
</>
);
}
function StaticExample() {
let [frequency setFrequency] = ReactuseState();
return (
<>
<Picker
label="Choose frequency"
onSelectionChange=(selected) =>
setFrequency(selected)
>
<Item key="Rarely">Rarely</Item>
<Item key="Sometimes">Sometimes</Item>
<Item key="Always">Always</Item>
</Picker>
<p>You selected frequency</p>
</>
);
}
function StaticExample() {
let [
frequency
setFrequency
] = ReactuseState();
return (
<>
<Picker
label="Choose frequency"
onSelectionChange=(
selected
) =>
setFrequency(
selected
)
>
<Item key="Rarely">
Rarely
</Item>
<Item key="Sometimes">
Sometimes
</Item>
<Item key="Always">
Always
</Item>
</Picker>
<p>
You selected' '
frequency
</p>
</>
);
}
When using Picker with dynamic items, selection works much the same way using key
. However, if your data already has an id
property (as is common with many data sets), Picker can use that id without needing to specify a key
prop. The below example shows Picker using the id of each item from the items
array as the selected value without the need for key
. Note that key
will always take precedence if set.
function DynamicExample() {
let [animalId setAnimalId] = ReactuseState();
let options = [
{id: 1 name: 'Aardvark'}
{id: 2 name: 'Cat'}
{id: 3 name: 'Dog'}
{id: 4 name: 'Kangaroo'}
{id: 5 name: 'Koala'}
{id: 6 name: 'Penguin'}
{id: 7 name: 'Snake'}
{id: 8 name: 'Turtle'}
{id: 9 name: 'Wombat'}
];
return (
<>
<Picker
label="Pick an animal"
items= options
onSelectionChange=(selected) => setAnimalId(selected)>
(item) => <Item> itemname</Item>
</Picker>
<p>Your favorite animal has id: animalId</p>
</>
);
}
function DynamicExample() {
let [animalId setAnimalId] = ReactuseState();
let options = [
{id: 1 name: 'Aardvark'}
{id: 2 name: 'Cat'}
{id: 3 name: 'Dog'}
{id: 4 name: 'Kangaroo'}
{id: 5 name: 'Koala'}
{id: 6 name: 'Penguin'}
{id: 7 name: 'Snake'}
{id: 8 name: 'Turtle'}
{id: 9 name: 'Wombat'}
];
return (
<>
<Picker
label="Pick an animal"
items= options
onSelectionChange=(selected) =>
setAnimalId(selected)
>
(item) => <Item> itemname</Item>
</Picker>
<p>Your favorite animal has id: animalId</p>
</>
);
}
function DynamicExample() {
let [
animalId
setAnimalId
] = ReactuseState();
let options = [
{
id: 1
name: 'Aardvark'
}
{id: 2 name: 'Cat'}
{id: 3 name: 'Dog'}
{
id: 4
name: 'Kangaroo'
}
{
id: 5
name: 'Koala'
}
{
id: 6
name: 'Penguin'
}
{
id: 7
name: 'Snake'
}
{
id: 8
name: 'Turtle'
}
{
id: 9
name: 'Wombat'
}
];
return (
<>
<Picker
label="Pick an animal"
items= options
onSelectionChange=(
selected
) =>
setAnimalId(
selected
)
>
(item) => (
<Item>
itemname
</Item>
)
</Picker>
<p>
Your favorite
animal has id:' '
animalId
</p>
</>
);
}
Complex items#
Items within Picker also allow for additional content used to better communicate options. Icons and descriptions can be added to the children
of Item
as shown in the example below. If a description is added, the prop slot="description"
must be used to distinguish the different <Text>
elements.
<Picker label="Options">
<Section title="Permission">
<Item textValue="Read">
<Book size="S" />
<Text>Read</Text>
<Text slot="description">Read Only</Text>
</Item>
<Item textValue="Write">
<Draw size="S" />
<Text>Write</Text>
<Text slot="description">Read and Write Only</Text>
</Item>
<Item textValue="Admin">
<BulkEditUsers size="S" />
<Text>Admin</Text>
<Text slot="description">Full access</Text>
</Item>
</Section>
</Picker>
<Picker label="Options">
<Section title="Permission">
<Item textValue="Read">
<Book size="S" />
<Text>Read</Text>
<Text slot="description">Read Only</Text>
</Item>
<Item textValue="Write">
<Draw size="S" />
<Text>Write</Text>
<Text slot="description">Read and Write Only</Text>
</Item>
<Item textValue="Admin">
<BulkEditUsers size="S" />
<Text>Admin</Text>
<Text slot="description">Full access</Text>
</Item>
</Section>
</Picker>
<Picker label="Options">
<Section title="Permission">
<Item textValue="Read">
<Book size="S" />
<Text>Read</Text>
<Text slot="description">
Read Only
</Text>
</Item>
<Item textValue="Write">
<Draw size="S" />
<Text>
Write
</Text>
<Text slot="description">
Read and Write
Only
</Text>
</Item>
<Item textValue="Admin">
<BulkEditUsers size="S" />
<Text>
Admin
</Text>
<Text slot="description">
Full access
</Text>
</Item>
</Section>
</Picker>
Asynchronous loading#
Picker supports loading data asynchronously, and will display a progress circle when the isLoading
prop is set.
It also supports infinite scrolling to load more data on demand as the user scrolls, via the onLoadMore
prop.
This example uses the useAsyncList hook to handle loading the data. See the docs for more information.
import {useAsyncList} from '@react-stately/data';
function AsyncLoadingExample() {
let list = useAsyncList({
async load({signal cursor}) {
// If no cursor is available, then we're loading the first page.
// Otherwise, the cursor is the next URL to load, as returned from the previous page.
let res = await fetch(cursor || 'https://pokeapi.co/api/v2/pokemon' {
signal
});
let json = await resjson();
return {
items: jsonresults
cursor: jsonnext
};
}
});
return (
<Picker
label="Pick a Pokemon"
items= listitems
isLoading= listisLoading
onLoadMore= listloadMore>
(item) => <Item key= itemname> itemname</Item>
</Picker>
);
}
import {useAsyncList} from '@react-stately/data';
function AsyncLoadingExample() {
let list = useAsyncList({
async load({signal cursor}) {
// If no cursor is available, then we're loading the first page.
// Otherwise, the cursor is the next URL to load, as returned from the previous page.
let res = await fetch(
cursor || 'https://pokeapi.co/api/v2/pokemon'
{
signal
}
);
let json = await resjson();
return {
items: jsonresults
cursor: jsonnext
};
}
});
return (
<Picker
label="Pick a Pokemon"
items= listitems
isLoading= listisLoading
onLoadMore= listloadMore>
(item) => <Item key= itemname> itemname</Item>
</Picker>
);
}
import {useAsyncList} from '@react-stately/data';
function AsyncLoadingExample() {
let list = useAsyncList(
{
async load({
signal
cursor
}) {
// If no cursor is available, then we're loading the first page.
// Otherwise, the cursor is the next URL to load, as returned from the previous page.
let res = await fetch(
cursor ||
'https://pokeapi.co/api/v2/pokemon'
{
signal
}
);
let json = await resjson();
return {
items:
jsonresults
cursor:
jsonnext
};
}
}
);
return (
<Picker
label="Pick a Pokemon"
items= listitems
isLoading=
listisLoading
onLoadMore=
listloadMore
>
(item) => (
<Item
key=
itemname
>
itemname
</Item>
)
</Picker>
);
}
Props#
Name | Type | Default | Description |
isQuiet | boolean | — | Whether the textfield should be displayed with a quiet style. |
align | Alignment | "start" | Alignment of the menu relative to the input target |
direction | 'bottom' | 'top' | "bottom" | Direction the menu will render relative to the Picker |
menuWidth | DimensionValue | — | Width of the menu |
name | string | — | |
isOpen | boolean | — | Sets the open state of the menu |
defaultOpen | boolean | — | Sets the default open state of the menu |
shouldFlip | boolean | — | Whether the menu should automatically flip direction when space is limited |
children | ReactElement<SectionProps<T>> | ReactElement<ItemProps<T>> | ReactElement<SectionProps<T>> | ReactElement<ItemProps<T>>[] | (
(item: T
)) => ReactElement<SectionProps<T>> | ReactElement<ItemProps<T>> | — | The contents of the collection. |
disabledKeys | Iterable<Key> | — | They item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with. |
items | Iterable<T> | — | Item objects in the collection or section. |
isLoading | boolean | — | Whether the items are currently loading. |
isDisabled | boolean | — | Whether the input is disabled. |
isRequired | boolean | — | Whether user input is required on the input before form submission.
Often paired with the necessityIndicator prop to add a visual indicator to the input. |
validationState | ValidationState | — | Whether the input should display its "valid" or "invalid" visual styling. |
isReadOnly | boolean | — | Whether the input can be selected but not changed by the user. |
label | ReactNode | — | The content to display as the label. |
placeholder | string | — | Temporary text that occupies the text input when it is empty. |
disallowEmptySelection | boolean | — | Whether the collection allows empty selection. |
selectedKey | Key | — | The currently selected key in the collection (controlled). |
defaultSelectedKey | Key | — | The initial selected key in the collection (uncontrolled). |
labelPosition | LabelPosition | "top" | The label's overall position relative to the element it is labeling. |
labelAlign | Alignment | "start" | The label's horizontal alignment relative to the element it is labeling. |
necessityIndicator | NecessityIndicator | "icon" | Whether the required state should be shown as an icon or text. |
UNSAFE_className | string | — | |
UNSAFE_style | CSSProperties | — |
Events
Name | Type | Default | Description |
onOpenChange | (
(isOpen: boolean
)) => void | — | Method that is called when the open state of the menu changes |
onLoadMore | (
(
)) => any | — | Handler that is called when more items should be loaded, e.g. while scrolling near the bottom. |
onSelectionChange | (
(key: Key
)) => any | — | Handler that is called when the selection changes. |
Layout
Name | Type | Default | Description |
flex | string | number | boolean | — | |
flexGrow | number | — | |
flexShrink | number | — | |
flexBasis | number | 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' | — | |
flexOrder | number | — | |
gridArea | string | — | |
gridColumn | string | — | |
gridRow | string | — | |
gridColumnStart | string | — | |
gridColumnEnd | string | — | |
gridRowStart | string | — | |
gridRowEnd | string | — |
Spacing
Name | Type | Default | Description |
margin | DimensionValue | — | |
marginTop | DimensionValue | — | |
marginLeft | DimensionValue | — | |
marginRight | DimensionValue | — | |
marginBottom | DimensionValue | — | |
marginStart | DimensionValue | — | |
marginEnd | DimensionValue | — | |
marginX | DimensionValue | — | |
marginY | DimensionValue | — |
Sizing
Name | Type | Default | Description |
width | DimensionValue | — | |
minWidth | DimensionValue | — | |
maxWidth | DimensionValue | — | |
height | DimensionValue | — | |
minHeight | DimensionValue | — | |
maxHeight | DimensionValue | — |
Positioning
Name | Type | Default | Description |
position | 'static'
| 'relative'
| 'absolute'
| 'fixed'
| 'sticky' | — | |
top | DimensionValue | — | |
bottom | DimensionValue | — | |
left | DimensionValue | — | |
right | DimensionValue | — | |
start | DimensionValue | — | |
end | DimensionValue | — | |
zIndex | number | — | |
isHidden | boolean | — |
Accessibility
Name | Type | Default | Description |
id | string | — | |
aria-label | string | — | Defines a string value that labels the current element. |
aria-labelledby | string | — | Identifies the element (or elements) that labels the current element. |
aria-describedby | string | — | Identifies the element (or elements) that describes the object. |
aria-details | string | — | Identifies the element (or elements) that provide a detailed, extended description for the object. |
Visual options#
Label alignment#
<Picker label="Choose frequency" labelAlign="end">
<Item key="rarely">Rarely</Item>
<Item key="sometimes">Sometimes</Item>
<Item key="always">Always</Item>
</Picker>
<Picker label="Choose frequency" labelAlign="end">
<Item key="rarely">Rarely</Item>
<Item key="sometimes">Sometimes</Item>
<Item key="always">Always</Item>
</Picker>
<Picker
label="Choose frequency"
labelAlign="end">
<Item key="rarely">
Rarely
</Item>
<Item key="sometimes">
Sometimes
</Item>
<Item key="always">
Always
</Item>
</Picker>
Label position#
<Picker label="Choose frequency" labelPosition="side">
<Item key="rarely">Rarely</Item>
<Item key="sometimes">Sometimes</Item>
<Item key="always">Always</Item>
</Picker>
<Picker label="Choose frequency" labelPosition="side">
<Item key="rarely">Rarely</Item>
<Item key="sometimes">Sometimes</Item>
<Item key="always">Always</Item>
</Picker>
<Picker
label="Choose frequency"
labelPosition="side">
<Item key="rarely">
Rarely
</Item>
<Item key="sometimes">
Sometimes
</Item>
<Item key="always">
Always
</Item>
</Picker>
Quiet#
<Picker label="Choose frequency" isQuiet labelPosition="side">
<Item key="rarely">Rarely</Item>
<Item key="sometimes">Sometimes</Item>
<Item key="always">Always</Item>
</Picker>
<Picker
label="Choose frequency"
isQuiet
labelPosition="side">
<Item key="rarely">Rarely</Item>
<Item key="sometimes">Sometimes</Item>
<Item key="always">Always</Item>
</Picker>
<Picker
label="Choose frequency"
isQuiet
labelPosition="side">
<Item key="rarely">
Rarely
</Item>
<Item key="sometimes">
Sometimes
</Item>
<Item key="always">
Always
</Item>
</Picker>
Disabled#
<Picker label="Choose frequency" isDisabled>
<Item key="rarely">Rarely</Item>
<Item key="sometimes">Sometimes</Item>
<Item key="always">Always</Item>
</Picker>
<Picker label="Choose frequency" isDisabled>
<Item key="rarely">Rarely</Item>
<Item key="sometimes">Sometimes</Item>
<Item key="always">Always</Item>
</Picker>
<Picker
label="Choose frequency"
isDisabled>
<Item key="rarely">
Rarely
</Item>
<Item key="sometimes">
Sometimes
</Item>
<Item key="always">
Always
</Item>
</Picker>
Custom widths#
<Flex flexDirection="column">
<Picker label="Choose frequency" width="size-6000">
<Item key="rarely">Rarely</Item>
<Item key="sometimes">Sometimes</Item>
<Item key="always">Always</Item>
</Picker>
<Picker label="Choose animal" menuWidth="size-6000">
<Item key="Emu">Emu</Item>
<Item key="Kangaroo">Kangaroo</Item>
<Item key="Platypus">Platypus</Item>
</Picker>
</Flex>
<Flex flexDirection="column">
<Picker label="Choose frequency" width="size-6000">
<Item key="rarely">Rarely</Item>
<Item key="sometimes">Sometimes</Item>
<Item key="always">Always</Item>
</Picker>
<Picker label="Choose animal" menuWidth="size-6000">
<Item key="Emu">Emu</Item>
<Item key="Kangaroo">Kangaroo</Item>
<Item key="Platypus">Platypus</Item>
</Picker>
</Flex>
<Flex flexDirection="column">
<Picker
label="Choose frequency"
width="size-6000">
<Item key="rarely">
Rarely
</Item>
<Item key="sometimes">
Sometimes
</Item>
<Item key="always">
Always
</Item>
</Picker>
<Picker
label="Choose animal"
menuWidth="size-6000">
<Item key="Emu">
Emu
</Item>
<Item key="Kangaroo">
Kangaroo
</Item>
<Item key="Platypus">
Platypus
</Item>
</Picker>
</Flex>
Align and direction#
<Flex flexDirection="column">
<Picker label="Choose frequency" align="end" menuWidth="size-3000">
<Item key="rarely">Rarely</Item>
<Item key="sometimes">Sometimes</Item>
<Item key="always">Always</Item>
</Picker>
<Picker label="Choose animal" direction="top">
<Item key="Emu">Emu</Item>
<Item key="Kangaroo">Kangaroo</Item>
<Item key="Platypus">Platypus</Item>
</Picker>
</Flex>
<Flex flexDirection="column">
<Picker
label="Choose frequency"
align="end"
menuWidth="size-3000">
<Item key="rarely">Rarely</Item>
<Item key="sometimes">Sometimes</Item>
<Item key="always">Always</Item>
</Picker>
<Picker label="Choose animal" direction="top">
<Item key="Emu">Emu</Item>
<Item key="Kangaroo">Kangaroo</Item>
<Item key="Platypus">Platypus</Item>
</Picker>
</Flex>
<Flex flexDirection="column">
<Picker
label="Choose frequency"
align="end"
menuWidth="size-3000">
<Item key="rarely">
Rarely
</Item>
<Item key="sometimes">
Sometimes
</Item>
<Item key="always">
Always
</Item>
</Picker>
<Picker
label="Choose animal"
direction="top">
<Item key="Emu">
Emu
</Item>
<Item key="Kangaroo">
Kangaroo
</Item>
<Item key="Platypus">
Platypus
</Item>
</Picker>
</Flex>
Menu state#
The open state of the menu can be controlled via the defaultOpen
and isOpen
props
function Example() {
let [open setOpen] = ReactuseState(false);
let [frequency setfrequency] = ReactuseState("always");
return (
<Picker
label="Frequency"
isOpen= open
selectedKey= frequency
onOpenChange= setOpen
onSelectionChange= selected => setfrequency(selected)>
<Item key="rarely">Rarely</Item>
<Item key="sometimes">Sometimes</Item>
<Item key="always">Always</Item>
</Picker>
);
}
function Example() {
let [open setOpen] = ReactuseState(false);
let [frequency setfrequency] = ReactuseState('always');
return (
<Picker
label="Frequency"
isOpen= open
selectedKey= frequency
onOpenChange= setOpen
onSelectionChange=(selected) =>
setfrequency(selected)
>
<Item key="rarely">Rarely</Item>
<Item key="sometimes">Sometimes</Item>
<Item key="always">Always</Item>
</Picker>
);
}
function Example() {
let [
open
setOpen
] = ReactuseState(
false
);
let [
frequency
setfrequency
] = ReactuseState(
'always'
);
return (
<Picker
label="Frequency"
isOpen= open
selectedKey=
frequency
onOpenChange=
setOpen
onSelectionChange=(
selected
) =>
setfrequency(
selected
)
>
<Item key="rarely">
Rarely
</Item>
<Item key="sometimes">
Sometimes
</Item>
<Item key="always">
Always
</Item>
</Picker>
);
}