Skip to content

Commit

Permalink
[material-ui][Select] Fix MenuProps slotProps forwarding (#39177)
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoAndai committed Sep 27, 2023
1 parent 0be321e commit 99a1b85
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 23 deletions.
25 changes: 2 additions & 23 deletions packages/mui-material/src/Menu/Menu.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import * as React from 'react';
import { SxProps } from '@mui/system';
import { MenuOwnerState, SlotComponentProps } from '@mui/base';
import { InternalStandardProps as StandardProps } from '..';
import Paper, { PaperProps } from '../Paper';
import { PaperProps } from '../Paper';
import { PopoverProps } from '../Popover';
import { MenuListProps } from '../MenuList';
import { Theme } from '../styles';
import { TransitionProps } from '../transitions/transition';
import { MenuClasses } from './menuClasses';

export interface MenuProps
extends StandardProps<Omit<PopoverProps, 'slots' | 'slotProps'>, 'children'> {
export interface MenuProps extends StandardProps<PopoverProps> {
/**
* An HTML element, or a function that returns one.
* It's used to set the position of the menu.
Expand Down Expand Up @@ -60,25 +58,6 @@ export interface MenuProps
* `classes` prop applied to the [`Popover`](/material-ui/api/popover/) element.
*/
PopoverClasses?: PopoverProps['classes'];
/**
* The components used for each slot inside.
*
* @default {}
*/
slots?: {
root?: React.ElementType;
paper?: React.ElementType;
};
/**
* The extra props for the slot components.
* You can override the existing props or add new ones.
*
* @default {}
*/
slotProps?: {
root?: SlotComponentProps<typeof Menu, {}, MenuOwnerState>;
paper?: SlotComponentProps<typeof Paper, {}, {}>;
};
/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
Expand Down
17 changes: 17 additions & 0 deletions packages/mui-material/src/Select/Select.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,21 @@ function genericValueTest() {
},
},
});

// tests deep slot prop forwarding up to the modal backdrop
<Select
MenuProps={{
slotProps: {
root: {
slotProps: {
backdrop: {
style: {
backgroundColor: 'transparent',
},
},
},
},
},
}}
/>;
}
25 changes: 25 additions & 0 deletions packages/mui-material/src/Select/Select.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,31 @@ describe('<Select />', () => {

expect(paper.style).to.have.property('minWidth', `${selectButton.clientWidth}px`);
});

// https://github.com/mui/material-ui/issues/38949
it('should forward `slotProps` to menu', function test() {
const { getByTestId } = render(
<Select
MenuProps={{
slotProps: {
root: {
slotProps: {
backdrop: { 'data-testid': 'backdrop', style: { backgroundColor: 'red' } },
},
},
},
}}
open
value="10"
>
<MenuItem value="10">Ten</MenuItem>
</Select>,
);

const backdrop = getByTestId('backdrop');

expect(backdrop.style).to.have.property('backgroundColor', 'red');
});
});

describe('prop: SelectDisplayProps', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/mui-material/src/Select/SelectInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
...MenuProps.MenuListProps,
}}
slotProps={{
...MenuProps.slotProps,
paper: {
...paperProps,
style: {
Expand Down

0 comments on commit 99a1b85

Please sign in to comment.