-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[Select] Improve categories support #18200
Comments
@nicks78 Please provide a full reproduction test case. This would help a lot 👷 . |
https://codesandbox.io/s/create-react-app-5z42i?fontsize=14 This is the reproduction with the error |
@oliviertassinari , I take the same exemple like it is in the library and there is still the same error : |
@nicks78 Thank you for the codesandbox. |
Any progress on bug 1 here? Anything I can do to help? This is a bit of a dealbreaker for the Select component as I obviously don't want my headers being selected. The native Select option seems to handle this properly. My current workaround is to add the following to my CSS stylesheet, but I know it's an ugly hack: .MuiListSubheader-root {
pointer-events: none;
} Perhaps putting a boolean prop on the ListSubheader that conditionally adds |
For a future iteration, let's not forget about the learnings of #19574. |
As mentioned in #20448: There is an accessibility bug when using |
Are there any workarounds for issue #2? |
@wseagar I'm not sure if adding |
Thanks @embeddedt For the moment I've used the native prop on the select with the native elements for the options This solves the above 2 issues for my use case (this example from the docs)
|
I found a better solution to this problem (It only solves if you have just one ListSubheader). In the select component, you can pass the So, you just have to do this: import * as React from 'react'
import MenuItem from '@material-ui/core/MenuItem'
import ListSubheader from '@material-ui/core/ListSubheader'
import Select, { SelectProps } from '@material-ui/core/Select'
interface Props {
subheaderText: string
}
function MySelect(props: Props) {
const { subheaderText } = props
const menuProps: SelectProps['MenuProps'] = React.useMemo(
() => ({
TransitionProps: { timeout: 0 },
MenuListProps: {
subheader: <ListSubheader component="div">{subheaderText}</ListSubheader>,
},
}),
[subheaderText]
)
return (
<Select MenuProps={menuProps}>
<MenuItem>0</MenuItem>
<MenuItem>1</MenuItem>
<MenuItem>2</MenuItem>
</Select>
)
} This way nothing will happen if the user clicks in the subheader and also the |
is it a problem to add one additional prop and one line of handler? facing the same issue and don't understand why it's not implemented for almost 2 years |
I was checking ListSubheader for some time, but couldn't manage to disable selection. Seems to me like an overkill to have a separate Component for the grouping menu item (ListSubheader), or at least seems like it should reuse much of the MenuItem functionality. A workaround that I used to fix the select issue on the ListSubheader is to use the simple MenuItem component, set "disabled" on it and styled it. Because disabled takes precedence over the custom style, I had to use !important on opacity.
|
I tried it on latest docs and it works ok. One suggestion, to show a demo example in docs where the "sticky" list subheader behavior can be noticed. https://next--material-ui.netlify.app/components/selects/#grouping |
Ad 1. Stopping propagation worked for me. |
Edit @oliviertassinari
bug 1
ListSubheader
shouldn't trigger the selection.bug 2
ListSubheader
should be visible when scrollingThe text was updated successfully, but these errors were encountered: