Skip to content

Commit 0bc8b24

Browse files
authored
fix: Picker default text display (#8959)
* fix: Picker SelectedValue default slot display * add an identifier so we can display the default text slot
1 parent bae7179 commit 0bc8b24

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

packages/@react-spectrum/s2/src/Picker.tsx

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ const PickerButton = createHideableComponent(function PickerButton<T extends obj
532532
})}>
533533
{(renderProps) => (
534534
<>
535-
<SelectValue className={valueStyles({isQuiet}) + ' ' + raw('&> :not([slot=icon], [slot=avatar], [slot=label]) {display: none;}')}>
535+
<SelectValue className={valueStyles({isQuiet}) + ' ' + raw('&> :not([slot=icon], [slot=avatar], [slot=label], [data-slot=label]) {display: none;}')}>
536536
{({selectedItems, defaultChildren}) => {
537537
return (
538538
<Provider
@@ -556,16 +556,24 @@ const PickerButton = createHideableComponent(function PickerButton<T extends obj
556556
[TextContext, {
557557
slots: {
558558
description: {},
559-
[DEFAULT_SLOT]: {styles: style({
560-
display: 'block',
561-
flexGrow: 1,
562-
truncate: true
563-
})},
564-
label: {styles: style({
565-
display: 'block',
566-
flexGrow: 1,
567-
truncate: true
568-
})}
559+
[DEFAULT_SLOT]: {
560+
styles: style({
561+
display: 'block',
562+
flexGrow: 1,
563+
truncate: true
564+
}),
565+
// @ts-ignore
566+
'data-slot': 'label'
567+
},
568+
label: {
569+
styles: style({
570+
display: 'block',
571+
flexGrow: 1,
572+
truncate: true
573+
}),
574+
// @ts-ignore not technically necessary, but good for consistency
575+
'data-slot': 'label'
576+
}
569577
}
570578
}],
571579
[InsideSelectValueContext, true]

packages/@react-spectrum/s2/stories/Picker.stories.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,17 @@ export const WithAvatars: Story = {
153153
<Picker {...args}>
154154
<PickerItem textValue="User One">
155155
<Avatar slot="avatar" src={SRC_URL_1} />
156-
<Text slot="label">User One</Text>
156+
<Text>User One</Text>
157157
<Text slot="description">[email protected]</Text>
158158
</PickerItem>
159159
<PickerItem textValue="User Two">
160160
<Avatar slot="avatar" src={SRC_URL_2} />
161-
<Text slot="label">User Two</Text>
161+
<Text>User Two</Text>
162162
<Text slot="description">[email protected]<br />123-456-7890</Text>
163163
</PickerItem>
164164
<PickerItem textValue="User Three">
165165
<Avatar slot="avatar" src={SRC_URL_2} />
166-
<Text slot="label">User Three</Text>
166+
<Text>User Three</Text>
167167
</PickerItem>
168168
</Picker>
169169
),

0 commit comments

Comments
 (0)