Skip to content

Commit 2fd87d9

Browse files
authored
Example customizing selectvalue (#6425)
* Example showing custom selectvalue
1 parent 8c13146 commit 2fd87d9

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

packages/react-aria-components/docs/Select.mdx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,36 @@ function Example() {
833833
}
834834
```
835835

836+
## Customizing SelectValue
837+
838+
Select passes the rendered children of the selected item in the render props of the `SelectValue` as well as if the placeholder should be showing. You can use this to customize the value displayed in the Select.
839+
840+
```tsx example
841+
<Select>
842+
<Label>Favorite Animal</Label>
843+
<Button>
844+
{/*- begin highlight -*/}
845+
<SelectValue>
846+
{({defaultChildren, isPlaceholder}) => {
847+
return isPlaceholder ? <><b>Animal</b> selection</> : defaultChildren;
848+
}}
849+
</SelectValue>
850+
{/*- end highlight -*/}
851+
<span aria-hidden="true">▼</span>
852+
</Button>
853+
<Popover>
854+
<ListBox>
855+
<ListBoxItem>Aardvark</ListBoxItem>
856+
<ListBoxItem>Cat</ListBoxItem>
857+
<ListBoxItem>Dog</ListBoxItem>
858+
<ListBoxItem>Kangaroo</ListBoxItem>
859+
<ListBoxItem>Panda</ListBoxItem>
860+
<ListBoxItem>Snake</ListBoxItem>
861+
</ListBox>
862+
</Popover>
863+
</Select>
864+
```
865+
836866
## Props
837867

838868
### Select
@@ -995,7 +1025,7 @@ A [Button](Button.html) can be targeted with the `.react-aria-Button` CSS select
9951025

9961026
### SelectValue
9971027

998-
A `SelectValue` can be targed with the `.react-aria-SelectValue` CSS selector, or by overriding with a custom `className`. It supports the following states and render props:
1028+
A `SelectValue` can be targeted with the `.react-aria-SelectValue` CSS selector, or by overriding with a custom `className`. It supports the following states and render props:
9991029

10001030
<StateTable properties={docs.exports.SelectValueRenderProps.properties} />
10011031

0 commit comments

Comments
 (0)