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] Add 'onColumnHeaderContextMenu' event #14734

Merged
merged 7 commits into from
Oct 8, 2024
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
8 changes: 8 additions & 0 deletions docs/data/data-grid/events/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@
"event": "MuiEvent<React.MouseEvent<HTMLElement>>",
"componentProp": "onColumnHeaderClick"
},
{
"projects": ["x-data-grid", "x-data-grid-pro", "x-data-grid-premium"],
"name": "columnHeaderContextMenu",
"description": "Fired when the user attempts to open a context menu in the column header.",
"params": "GridColumnHeaderParams",
"event": "MuiEvent<React.MouseEvent<HTMLElement>>",
"componentProp": "onColumnHeaderContextMenu"
},
{
"projects": ["x-data-grid", "x-data-grid-pro", "x-data-grid-premium"],
"name": "columnHeaderDoubleClick",
Expand Down
7 changes: 7 additions & 0 deletions docs/pages/x/api/data-grid/data-grid-premium.json
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,13 @@
"describedArgs": ["params", "event", "details"]
}
},
"onColumnHeaderContextMenu": {
"type": { "name": "func" },
"signature": {
"type": "function(params: GridColumnHeaderParams, event: MuiEvent<React.MouseEvent>) => void",
"describedArgs": ["params", "event"]
}
},
"onColumnHeaderDoubleClick": {
"type": { "name": "func" },
"signature": {
Expand Down
7 changes: 7 additions & 0 deletions docs/pages/x/api/data-grid/data-grid-pro.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,13 @@
"describedArgs": ["params", "event", "details"]
}
},
"onColumnHeaderContextMenu": {
"type": { "name": "func" },
"signature": {
"type": "function(params: GridColumnHeaderParams, event: MuiEvent<React.MouseEvent>) => void",
"describedArgs": ["params", "event"]
}
},
"onColumnHeaderDoubleClick": {
"type": { "name": "func" },
"signature": {
Expand Down
7 changes: 7 additions & 0 deletions docs/pages/x/api/data-grid/data-grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@
"describedArgs": ["params", "event", "details"]
}
},
"onColumnHeaderContextMenu": {
"type": { "name": "func" },
"signature": {
"type": "function(params: GridColumnHeaderParams, event: MuiEvent<React.MouseEvent>) => void",
"describedArgs": ["params", "event"]
}
},
"onColumnHeaderDoubleClick": {
"type": { "name": "func" },
"signature": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,13 @@
"details": "Additional details for this callback."
}
},
"onColumnHeaderContextMenu": {
"description": "Callback fired when a contextmenu event comes from a column header element.",
"typeDescriptions": {
"params": "With all properties from GridColumnHeaderParams.",
"event": "The event object."
}
},
"onColumnHeaderDoubleClick": {
"description": "Callback fired when a double click event comes from a column header element.",
"typeDescriptions": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,13 @@
"details": "Additional details for this callback."
}
},
"onColumnHeaderContextMenu": {
"description": "Callback fired when a contextmenu event comes from a column header element.",
"typeDescriptions": {
"params": "With all properties from GridColumnHeaderParams.",
"event": "The event object."
}
},
"onColumnHeaderDoubleClick": {
"description": "Callback fired when a double click event comes from a column header element.",
"typeDescriptions": {
Expand Down
7 changes: 7 additions & 0 deletions docs/translations/api-docs/data-grid/data-grid/data-grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@
"details": "Additional details for this callback."
}
},
"onColumnHeaderContextMenu": {
"description": "Callback fired when a contextmenu event comes from a column header element.",
"typeDescriptions": {
"params": "With all properties from GridColumnHeaderParams.",
"event": "The event object."
}
},
"onColumnHeaderDoubleClick": {
"description": "Callback fired when a double click event comes from a column header element.",
"typeDescriptions": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,12 @@ DataGridPremiumRaw.propTypes = {
* @param {GridCallbackDetails} details Additional details for this callback.
*/
onColumnHeaderClick: PropTypes.func,
/**
* Callback fired when a contextmenu event comes from a column header element.
* @param {GridColumnHeaderParams} params With all properties from [[GridColumnHeaderParams]].
* @param {MuiEvent<React.MouseEvent>} event The event object.
*/
onColumnHeaderContextMenu: PropTypes.func,
/**
* Callback fired when a double click event comes from a column header element.
* @param {GridColumnHeaderParams} params With all properties from [[GridColumnHeaderParams]].
Expand Down
6 changes: 6 additions & 0 deletions packages/x-data-grid-pro/src/DataGridPro/DataGridPro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,12 @@ DataGridProRaw.propTypes = {
* @param {GridCallbackDetails} details Additional details for this callback.
*/
onColumnHeaderClick: PropTypes.func,
/**
* Callback fired when a contextmenu event comes from a column header element.
* @param {GridColumnHeaderParams} params With all properties from [[GridColumnHeaderParams]].
* @param {MuiEvent<React.MouseEvent>} event The event object.
*/
onColumnHeaderContextMenu: PropTypes.func,
/**
* Callback fired when a double click event comes from a column header element.
* @param {GridColumnHeaderParams} params With all properties from [[GridColumnHeaderParams]].
Expand Down
6 changes: 6 additions & 0 deletions packages/x-data-grid/src/DataGrid/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,12 @@ DataGridRaw.propTypes = {
* @param {GridCallbackDetails} details Additional details for this callback.
*/
onColumnHeaderClick: PropTypes.func,
/**
* Callback fired when a contextmenu event comes from a column header element.
* @param {GridColumnHeaderParams} params With all properties from [[GridColumnHeaderParams]].
* @param {MuiEvent<React.MouseEvent>} event The event object.
*/
onColumnHeaderContextMenu: PropTypes.func,
/**
* Callback fired when a double click event comes from a column header element.
* @param {GridColumnHeaderParams} params With all properties from [[GridColumnHeaderParams]].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ function GridColumnHeaderItem(props: GridColumnHeaderItemProps) {
const mouseEventsHandlers = React.useMemo(
() => ({
onClick: publish('columnHeaderClick'),
onContextMenu: publish('columnHeaderContextMenu'),
onDoubleClick: publish('columnHeaderDoubleClick'),
onMouseOver: publish('columnHeaderOver'), // TODO remove as it's not used
onMouseOut: publish('columnHeaderOut'), // TODO remove as it's not used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function useGridEvents(
DataGridProcessedProps,
| 'onColumnHeaderClick'
| 'onColumnHeaderDoubleClick'
| 'onColumnHeaderContextMenu'
| 'onColumnHeaderOver'
| 'onColumnHeaderOut'
| 'onColumnHeaderEnter'
Expand All @@ -30,6 +31,7 @@ export function useGridEvents(
>,
): void {
useGridApiOptionHandler(apiRef, 'columnHeaderClick', props.onColumnHeaderClick);
useGridApiOptionHandler(apiRef, 'columnHeaderContextMenu', props.onColumnHeaderContextMenu);
useGridApiOptionHandler(apiRef, 'columnHeaderDoubleClick', props.onColumnHeaderDoubleClick);
useGridApiOptionHandler(apiRef, 'columnHeaderOver', props.onColumnHeaderOver);
useGridApiOptionHandler(apiRef, 'columnHeaderOut', props.onColumnHeaderOut);
Expand Down
7 changes: 7 additions & 0 deletions packages/x-data-grid/src/models/events/gridEventLookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ export interface GridColumnHeaderEventLookup {
params: GridColumnHeaderParams;
event: React.MouseEvent<HTMLElement>;
};
/**
* Fired when the user attempts to open a context menu in the column header.
*/
columnHeaderContextMenu: {
params: GridColumnHeaderParams;
event: React.MouseEvent<HTMLElement>;
};
/**
* Fired when a column header is double-clicked.
*/
Expand Down
6 changes: 6 additions & 0 deletions packages/x-data-grid/src/models/props/DataGridProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,12 @@ export interface DataGridPropsWithoutDefaultValue<R extends GridValidRowModel =
* @param {GridCallbackDetails} details Additional details for this callback.
*/
onColumnHeaderClick?: GridEventListener<'columnHeaderClick'>;
/**
* Callback fired when a contextmenu event comes from a column header element.
* @param {GridColumnHeaderParams} params With all properties from [[GridColumnHeaderParams]].
* @param {MuiEvent<React.MouseEvent>} event The event object.
*/
onColumnHeaderContextMenu?: GridEventListener<'columnHeaderContextMenu'>;
/**
* Callback fired when a double click event comes from a column header element.
* @param {GridColumnHeaderParams} params With all properties from [[GridColumnHeaderParams]].
Expand Down
Loading