Skip to content

Commit 7bcc397

Browse files
[Select] Improve MenuProps.slotProps implementation (#46612)
1 parent 6c9df3c commit 7bcc397

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

packages/mui-material/src/Select/SelectInput.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,6 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
133133
...other
134134
} = props;
135135

136-
const paperProps = {
137-
...MenuProps.PaperProps,
138-
...MenuProps.slotProps?.paper,
139-
};
140-
141136
const [value, setValueState] = useControlled({
142137
controlled: valueProp,
143138
default: defaultValue,
@@ -158,6 +153,23 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
158153
const { current: isOpenControlled } = React.useRef(openProp != null);
159154
const [menuMinWidthState, setMenuMinWidthState] = React.useState();
160155

156+
const open = displayNode !== null && openState;
157+
158+
const ownerState = {
159+
...props,
160+
variant,
161+
value,
162+
open,
163+
error,
164+
};
165+
166+
const paperProps = {
167+
...MenuProps.PaperProps,
168+
...(typeof MenuProps.slotProps?.paper === 'function'
169+
? MenuProps.slotProps.paper(ownerState)
170+
: MenuProps.slotProps?.paper),
171+
};
172+
161173
const handleRef = useForkRef(ref, inputRefProp);
162174
const handlePaperRef = useForkRef(paperProps.ref, paperRef);
163175

@@ -219,8 +231,8 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
219231
return undefined;
220232
}, [labelId]);
221233

222-
const update = (open, event) => {
223-
if (open) {
234+
const update = (openParam, event) => {
235+
if (openParam) {
224236
if (onOpen) {
225237
onOpen(event);
226238
}
@@ -230,7 +242,7 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
230242

231243
if (!isOpenControlled) {
232244
setMenuMinWidthState(autoWidth ? null : anchorElement.clientWidth);
233-
setOpenState(open);
245+
setOpenState(openParam);
234246
}
235247
};
236248

@@ -360,8 +372,6 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
360372
}
361373
};
362374

363-
const open = displayNode !== null && openState;
364-
365375
const handleBlur = (event) => {
366376
// if open event.stopImmediatePropagation
367377
if (!open && onBlur) {
@@ -528,19 +538,13 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
528538

529539
const buttonId = SelectDisplayProps.id || (name ? `mui-component-select-${name}` : undefined);
530540

531-
const ownerState = {
532-
...props,
533-
variant,
534-
value,
535-
open,
536-
error,
537-
};
538-
539541
const classes = useUtilityClasses(ownerState);
540542

541543
const listProps = {
542544
...MenuProps.MenuListProps,
543-
...MenuProps.slotProps?.list,
545+
...(typeof MenuProps.slotProps?.list === 'function'
546+
? MenuProps.slotProps.list(ownerState)
547+
: MenuProps.slotProps?.list),
544548
};
545549

546550
const listboxId = useId();

0 commit comments

Comments
 (0)