Skip to content
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

[material-ui][Select] Fix MenuProps slotProps forwarding #39177

Merged
merged 2 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading