You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/data/material/components/selects/selects.md
+61Lines changed: 61 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -127,6 +127,67 @@ Display categories with the `ListSubheader` component or the native `<optgroup>`
127
127
128
128
{{"demo": "GroupedSelect.js"}}
129
129
130
+
:::warning
131
+
If you wish to wrap the ListSubheader in a custom component, you'll have to annotate it so Material UI can handle it properly when determining focusable elements.
132
+
133
+
You have two options for solving this:
134
+
Option 1: Define a static boolean field called `muiSkipListHighlight` on your component function, and set it to `true`:
135
+
136
+
```tsx
137
+
function MyListSubheader(props:ListSubheaderProps) {
138
+
return <ListSubheader{...props} />;
139
+
}
140
+
141
+
MyListSubheader.muiSkipListHighlight=true;
142
+
exportdefaultMyListSubheader;
143
+
144
+
// elsewhere:
145
+
146
+
return (
147
+
<Select>
148
+
<MyListSubheader>Group 1</MyListSubheader>
149
+
<MenuItemvalue={1}>Option 1</MenuItem>
150
+
<MenuItemvalue={2}>Option 2</MenuItem>
151
+
<MyListSubheader>Group 2</MyListSubheader>
152
+
<MenuItemvalue={3}>Option 3</MenuItem>
153
+
<MenuItemvalue={4}>Option 4</MenuItem>
154
+
{/* ... */}
155
+
</Select>
156
+
```
157
+
158
+
Option 2: Place a `muiSkipListHighlight` prop on each instance of your component.
159
+
The prop doesn't have to be forwarded to the ListSubheader, nor present in the underlying DOM element.
160
+
It just has to be placed on a component that's used as a subheader.
0 commit comments