-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Picker docs and fixes #441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Build successful! 🎉 |
|
Build successful! 🎉 |
|
Build successful! 🎉 |
|
Build successful! 🎉 |
|
Build successful! 🎉 |
|
Build successful! 🎉 |
|
Build successful! 🎉 |
|
Build successful! 🎉 |
|
Build successful! 🎉 |
|
|
||
| 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. The value to be passed to the `onSelectionChange` handler can be set via the `uniqueKey` prop. Alternatively, if the options dataset contains an `id` key, as shown in the example below, this can be used instead. See the <a href="#events" title="Events">events</a> section for more detail on selection. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value to be passed to the
onSelectionChangehandler can be set via theuniqueKeyprop.
This is a bit confusing. I think I'd say something like "Each item accepts a uniqueKey prop, which is passed to the onSelectionChange handler to identify the selected item."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Alternatively, if the item objects contain an id property, as shown in the example below, then this is used automatically and a uniqueKey prop is not required.
| ]; | ||
| let [animal, setAnimal] = React.useState("Bison"); | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra whitespace
| {item => <Item uniqueKey={item.name}>{item.name}</Item>} | ||
| </Picker> | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
| ### Static Items | ||
| ```tsx example | ||
| <Picker label="Pick an animal"> | ||
| <Section uniqueKey="Animals" title="Animals"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could remove the uniqueKey here, since it's static. React will assign a key automatically, and since it's not used for selection a manual key isn't needed.
|
|
||
| ### Static Items | ||
| ```tsx example | ||
| <Picker label="Pick an animal"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't all animals :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sometimes :)
| } | ||
| ``` | ||
|
|
||
| When using Picker with dynamic items, selection works much the same way using `uniqueKey`. However, if your data already has an `id` key (as is common with many data sets), Picker can use that id without needing to specify a `uniqueKey` prop. The below example shows Picker using the id of each item from the `items` array as the selected value without the need for `uniqueKey`. Note that `uniqueKey` will always take precedence if set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe say "id property" instead of "key"? I feel like key has an overloaded meaning
| ``` | ||
|
|
||
| ## Complex Items | ||
| Items within Picker also allow for additional content used to better communicate options. Icons, 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Icons, and descriptions"
| Items within Picker also allow for additional content used to better communicate options. Icons, 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. | ||
|
|
||
| ```tsx example | ||
| <Picker label="Options" > |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra space
|
Build successful! 🎉 |
|
Build successful! 🎉 |
The Picker docs