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] Allow to pass props to the TrapFocus inside the panel wrapper #7897

Merged
merged 2 commits into from
Feb 10, 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
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,17 @@ GridColumnsPanel.propTypes = {
// ----------------------------------------------------------------------
autoFocusSearchField: PropTypes.bool,
searchPredicate: PropTypes.func,
slotProps: PropTypes.shape({
TrapFocus: PropTypes.shape({
children: PropTypes.element.isRequired,
disableAutoFocus: PropTypes.bool,
disableEnforceFocus: PropTypes.bool,
disableRestoreFocus: PropTypes.bool,
getTabbable: PropTypes.func,
isEnabled: PropTypes.func,
open: PropTypes.bool.isRequired,
}),
}),
sort: PropTypes.oneOf(['asc', 'desc']),
} as any;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import TrapFocus from '@mui/material/Unstable_TrapFocus';
import TrapFocus, { TrapFocusProps } from '@mui/material/Unstable_TrapFocus';
import { styled, Theme } from '@mui/material/styles';
import { MUIStyledCommonProps } from '@mui/system';
import { unstable_composeClasses as composeClasses } from '@mui/material';
Expand Down Expand Up @@ -37,17 +38,21 @@ const isEnabled = () => true;

export interface GridPanelWrapperProps
extends React.PropsWithChildren<React.HTMLAttributes<HTMLDivElement>>,
MUIStyledCommonProps<Theme> {}
MUIStyledCommonProps<Theme> {
slotProps?: {
TrapFocus?: TrapFocusProps;
};
}

const GridPanelWrapper = React.forwardRef<HTMLDivElement, GridPanelWrapperProps>(
function GridPanelWrapper(props, ref) {
const { className, ...other } = props;
const { className, slotProps = {}, ...other } = props;
const rootProps = useGridRootProps();
const ownerState = { classes: rootProps.classes };
const classes = useUtilityClasses(ownerState);

return (
<TrapFocus open disableEnforceFocus isEnabled={isEnabled}>
<TrapFocus open disableEnforceFocus isEnabled={isEnabled} {...slotProps.TrapFocus}>
<GridPanelWrapperRoot
ref={ref}
tabIndex={-1}
Expand All @@ -59,4 +64,22 @@ const GridPanelWrapper = React.forwardRef<HTMLDivElement, GridPanelWrapperProps>
},
);

GridPanelWrapper.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "yarn proptypes" |
// ----------------------------------------------------------------------
slotProps: PropTypes.shape({
TrapFocus: PropTypes.shape({
children: PropTypes.element.isRequired,
disableAutoFocus: PropTypes.bool,
disableEnforceFocus: PropTypes.bool,
disableRestoreFocus: PropTypes.bool,
getTabbable: PropTypes.func,
isEnabled: PropTypes.func,
open: PropTypes.bool.isRequired,
}),
}),
} as any;

export { GridPanelWrapper };