-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Select][Joy] Fix forwarding listbox
component
prop (#34172)
- Loading branch information
1 parent
0f88b86
commit 0a66a26
Showing
7 changed files
with
99 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
test/regressions/fixtures/SelectJoy/GroupedOptionSelect.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/joy/Box'; | ||
import Select from '@mui/joy/Select'; | ||
import Option, { optionClasses } from '@mui/joy/Option'; | ||
import Chip from '@mui/joy/Chip'; | ||
import List from '@mui/joy/List'; | ||
import ListItemDecorator, { listItemDecoratorClasses } from '@mui/joy/ListItemDecorator'; | ||
import ListDivider from '@mui/joy/ListDivider'; | ||
import ListItem from '@mui/joy/ListItem'; | ||
import Typography from '@mui/joy/Typography'; | ||
import Check from '@mui/icons-material/Check'; | ||
|
||
export default function SelectGroupedOptions() { | ||
const group = { | ||
Land: ['Cat', 'Dog', 'Tiger', 'Reindeer', 'Raccoon'], | ||
Water: ['Dolphin', 'Flounder', 'Eel'], | ||
Air: ['Falcon', 'Winged Horse', 'Owl'], | ||
}; | ||
const colors = { | ||
Land: 'neutral', | ||
Water: 'primary', | ||
Air: 'success', | ||
}; | ||
return ( | ||
<Box sx={{ minHeight: 300 }}> | ||
<Select | ||
placeholder="Choose your animal" | ||
defaultListboxOpen | ||
componentsProps={{ | ||
listbox: { | ||
component: 'div', | ||
sx: { | ||
maxHeight: 240, | ||
overflow: 'auto', | ||
'--List-padding': '0px', | ||
}, | ||
}, | ||
}} | ||
sx={{ width: 240 }} | ||
> | ||
{Object.entries(group).map(([name, animals], index) => ( | ||
<React.Fragment key={name}> | ||
{index !== 0 && <ListDivider role="none" />} | ||
<List aria-labelledby={`select-group-${name}`} sx={{ '--List-decorator-size': '28px' }}> | ||
<ListItem id={`select-group-${name}`} sticky> | ||
<Typography level="body3" textTransform="uppercase" letterSpacing="md"> | ||
{name} ({animals.length}) | ||
</Typography> | ||
</ListItem> | ||
{animals.map((anim) => ( | ||
<Option | ||
key={anim} | ||
value={anim} | ||
label={ | ||
<React.Fragment> | ||
<Chip | ||
size="sm" | ||
color={colors[name]} | ||
sx={{ borderRadius: 'xs', mr: 1, ml: -0.5 }} | ||
> | ||
{name} | ||
</Chip>{' '} | ||
{anim} | ||
</React.Fragment> | ||
} | ||
sx={{ | ||
[`&.${optionClasses.selected} .${listItemDecoratorClasses.root}`]: { | ||
opacity: 1, | ||
}, | ||
}} | ||
> | ||
<ListItemDecorator sx={{ opacity: 0 }}> | ||
<Check /> | ||
</ListItemDecorator> | ||
{anim} | ||
</Option> | ||
))} | ||
</List> | ||
</React.Fragment> | ||
))} | ||
</Select> | ||
</Box> | ||
); | ||
} |