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

[DataGrid] Refactor: create base MenuList props #16481

Merged
merged 4 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ function GridActionsCell(props: GridActionsCellProps) {
className={gridClasses.menuList}
onKeyDown={handleListKeyDown}
aria-labelledby={buttonId}
variant="menu"
autoFocusItem
>
{menuButtons.map((button, index) =>
Expand Down
6 changes: 5 additions & 1 deletion packages/x-data-grid/src/material/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const baseSlots: GridBaseSlots = {
baseCircularProgress: MUICircularProgress,
baseDivider: MUIDivider,
baseLinearProgress: MUILinearProgress,
baseMenuList: MUIMenuList,
baseMenuList: BaseMenuList,
baseMenuItem: BaseMenuItem,
baseTextField: BaseTextField,
baseFormControl: MUIFormControl,
Expand All @@ -120,6 +120,10 @@ const materialSlots: GridBaseSlots & GridIconSlotsComponent = {

export default materialSlots;

function BaseMenuList(props: GridSlotProps['baseMenuList']) {
return <MUIMenuList {...props} />;
}

function BaseMenuItem(props: GridSlotProps['baseMenuItem']) {
const { inert, iconStart, iconEnd, children, ...other } = props;
if (inert) {
Expand Down
10 changes: 10 additions & 0 deletions packages/x-data-grid/src/models/gridBaseSlots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ export type IconButtonProps = Omit<ButtonProps, 'startIcon'> & {

export type DividerProps = {};

export type MenuListProps = {
ref?: Ref<HTMLUListElement>;
id?: string;
className?: string;
children?: React.ReactNode;
autoFocus?: boolean;
autoFocusItem?: boolean;
Comment on lines +43 to +44
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we instead of these have enum for autoFocus to cover both cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it but I chose to keep the API material compatible instead. I could be convinced to switch it though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that was the general approach so far (to be close to material) then let's leave it. Otherwise, I think that enum is more generic and neutral and more flexible for potential updates

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach is mixed, some components are directly compatibles, others are reworked when the material API is too hard to adapt for other design-systems. I'll leave it as it is for now, I might change it once I start implementing bindings for other design-systems.

onKeyDown?: React.KeyboardEventHandler;
};

export type MenuItemProps = {
autoFocus?: boolean;
children?: React.ReactNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type { ButtonProps as MUIButtonProps } from '@mui/material/Button';
import type { CheckboxProps } from '@mui/material/Checkbox';
import type { CircularProgressProps as MUICircularProgressProps } from '@mui/material/CircularProgress';
import type { LinearProgressProps as MUILinearProgressProps } from '@mui/material/LinearProgress';
import type { MenuListProps } from '@mui/material/MenuList';
import type { MenuItemProps as MUIMenuItemProps } from '@mui/material/MenuItem';
import type { FormControlProps } from '@mui/material/FormControl';
import type { SelectProps } from '@mui/material/Select';
Expand Down Expand Up @@ -41,6 +40,7 @@ import type {
DividerProps,
IconButtonProps,
LinearProgressProps,
MenuListProps,
MenuItemProps,
SkeletonProps,
TooltipProps,
Expand Down