-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: add Avatar support for ComboBoxItem and PickerItem #8931
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
Changes from 3 commits
a373806
b6e9288
da609c6
753b3db
894e49d
a24272d
804afae
865c517
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,7 @@ function Example() { | |
|
|
||
| ### Slots | ||
|
|
||
| `ComboBoxItem` supports icons, and `label` and `description` text slots. | ||
| `ComboBoxItem` supports icons, avatars, and `label` and `description` text slots. | ||
|
|
||
| ```tsx render | ||
| "use client"; | ||
|
|
@@ -83,6 +83,30 @@ import UserSettings from '@react-spectrum/s2/icons/UserSettings'; | |
| </ComboBox> | ||
| ``` | ||
|
|
||
| ```tsx render | ||
| "use client"; | ||
| import {Avatar, ComboBox, ComboBoxItem, Text} from '@react-spectrum/s2'; | ||
|
|
||
| const users = Array.from({length: 10}, (_, i) => ({ | ||
| id: `user${i + 1}`, | ||
| name: `User ${i + 1}`, | ||
| email: `user${i + 1}@example.com`, | ||
| avatar: 'https://i.imgur.com/kJOwAdv.png' | ||
| })); | ||
|
|
||
| <ComboBox label="Share" items={users}> | ||
| {(item) => ( | ||
| <ComboBoxItem id={item.id} textValue={item.name}> | ||
| {/*- begin highlight -*/} | ||
| <Avatar slot="avatar" src={item.avatar} /> | ||
| {/*- end highlight -*/} | ||
| <Text slot="label">{item.name}</Text> | ||
| <Text slot="description">{item.email}</Text> | ||
| </ComboBoxItem> | ||
| )} | ||
| </ComboBox> | ||
| ``` | ||
|
||
|
|
||
| <InlineAlert variant="notice"> | ||
| <Heading>Accessibility</Heading> | ||
| <Content>Interactive elements (e.g. buttons) within picker items are not allowed. This will break keyboard and screen reader navigation. Only add textual or decorative graphics (e.g. icons) as children.</Content> | ||
|
|
||
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.
I think rather than adding this prop we could just make Avatar have CenterBaseline by default. I can't really think of a case where you'd want to align text with it at the bottom. We may be able to avoid the extra wrapper div as well since Image already has a wrapper div. We could potentially put the
::beforedirectly on that.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.
Thanks for fixing this!