Skip to content
Open
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 @@ -23,7 +23,7 @@ function CustomToolbar({ setFilterButtonEl }) {
);
}

export default function CustomFilterPanelPosition() {
export default function CustomFilterPanelPositionNoSnap() {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Since this demo customizes the panel placement that is not visible when the screenshot is taken, I've excluded it from being screenshoted.

const { data, loading } = useDemoData({
dataSet: 'Employee',
visibleFields: VISIBLE_FIELDS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function CustomToolbar({ setFilterButtonEl }: GridSlotProps['toolbar']) {
);
}

export default function CustomFilterPanelPosition() {
export default function CustomFilterPanelPositionNoSnap() {
const { data, loading } = useDemoData({
dataSet: 'Employee',
visibleFields: VISIBLE_FIELDS,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as React from 'react';
import { DataGrid } from '@mui/x-data-grid';
import { useDemoData } from '@mui/x-data-grid-generator';

const VISIBLE_FIELDS = ['name', 'rating', 'country', 'dateCreated', 'isAdmin'];

export default function FilterPanelPlacementColumnHeadersNoSnap() {
const { data, loading } = useDemoData({
dataSet: 'Employee',
visibleFields: VISIBLE_FIELDS,
rowLength: 100,
});

const columnHeadersRef = React.useRef(null);

return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid
{...data}
loading={loading}
showToolbar
slotProps={{
columnHeaders: {
ref: columnHeadersRef,
},
panel: {
placement: 'bottom-start',
target: columnHeadersRef.current,
},
}}
/>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as React from 'react';
import { DataGrid } from '@mui/x-data-grid';
import { useDemoData } from '@mui/x-data-grid-generator';

const VISIBLE_FIELDS = ['name', 'rating', 'country', 'dateCreated', 'isAdmin'];

export default function FilterPanelPlacementColumnHeadersNoSnap() {
const { data, loading } = useDemoData({
dataSet: 'Employee',
visibleFields: VISIBLE_FIELDS,
rowLength: 100,
});

const columnHeadersRef = React.useRef<HTMLDivElement>(null);

return (
<div style={{ height: 400, width: '100%' }}>
<DataGrid
{...data}
loading={loading}
showToolbar
slotProps={{
columnHeaders: {
ref: columnHeadersRef,
},
panel: {
placement: 'bottom-start',
target: columnHeadersRef.current,
},
}}
/>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<DataGrid
{...data}
loading={loading}
showToolbar
slotProps={{
columnHeaders: {
ref: columnHeadersRef,
},
panel: {
placement: 'bottom-start',
target: columnHeadersRef.current,
},
}}
/>
10 changes: 9 additions & 1 deletion docs/data/data-grid/filtering/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,17 @@ To pass props directly to the `InputComponent` and not its wrapper, you can use

### Customize the filter panel position

#### Toolbar button anchor

The demo below shows how to anchor the filter panel to the toolbar button instead of the column header.

{{"demo": "CustomFilterPanelPosition.js", "bg": "inline", "defaultCodeOpen": false}}
{{"demo": "CustomFilterPanelPositionNoSnap.js", "bg": "inline", "defaultCodeOpen": false}}

#### Column headers anchor

The following demo shows how to make panels always appear on the bottom-left under the column headers mimicking the default behavior of Data Grid v7.

{{"demo": "FilterPanelPlacementColumnHeadersNoSnap.js", "bg": "inline", "defaultCodeOpen": false}}

## API

Expand Down
42 changes: 38 additions & 4 deletions packages/x-data-grid/src/components/panel/GridPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ export interface GridPanelClasses {
paper: string;
}

export interface GridPanelProps extends Pick<
GridSlotProps['basePopper'],
'id' | 'className' | 'target' | 'flip'
> {
export interface GridPanelProps extends Omit<GridSlotProps['basePopper'], 'ref'> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(1) This widening exposes the on* handlers (onDidShow, onDidHide, onClickAway, and the clickAway*Event props) through slotProps.panel, but they are controlled internally.

The {...other} spread runs after onDidShow={onDidShow}, so a consumer override stops setIsPlaced(true) from firing. Then {isPlaced && children} never renders the panel content. Same path breaks onClickAway and onDidHide.

I think it is safer to keep the existing Pick and only add props with a clear use case. placement is the real motivation here, and boolean toggles like focusTrap are safe because they cannot break behavior.

Could be something like this:

Pick<
  GridSlotProps['basePopper'],
  'id' | 'className' | 'target' | 'flip' | 'placement' | 'focusTrap'
>

For the on* handlers, maybe hold off for now. They are risky without a real example or doc showing how to compose them with the internal handlers. Keeping the fix small avoids advertising a footgun.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(2) Minor: with this Omit, GridPanelProps now inherits a required open: boolean from PopperProps (gridBaseSlots.ts:211). So the open: boolean re-declaration on line 33 is identical and dead. Please drop that line.

onClose is not in PopperProps, so keep it.

-  open: boolean;
   onClose?: () => void;

ref?: React.Ref<HTMLDivElement>;
children?: React.ReactNode;
/**
Expand Down Expand Up @@ -134,11 +131,48 @@ GridPanel.propTypes = {
*/
classes: PropTypes.object,
className: PropTypes.string,
clickAwayMouseEvent: PropTypes.oneOf([
'onClick',
'onMouseDown',
'onMouseUp',
'onPointerDown',
'onPointerUp',
false,
]),
clickAwayTouchEvent: PropTypes.oneOf(['onTouchEnd', 'onTouchStart', false]),
flip: PropTypes.bool,
focusTrap: PropTypes.bool,
id: PropTypes.string,
onClickAway: PropTypes.func,
onClose: PropTypes.func,
onDidHide: PropTypes.func,
onDidShow: PropTypes.func,
onExited: PropTypes.func,
open: PropTypes.bool.isRequired,
/**
* @default 'bottom'
*/
placement: PropTypes.oneOf([
'auto-end',
'auto-start',
'auto',
'bottom-end',
'bottom-start',
'bottom',
'left-end',
'left-start',
'left',
'right-end',
'right-start',
'right',
'top-end',
'top-start',
'top',
]),
role: PropTypes.string,
style: PropTypes.object,
target: PropTypes /* @typescript-to-proptypes-ignore */.any,
transition: PropTypes.bool,
} as any;

export { GridPanel };
Loading