-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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] Toggling the checkbox using space exits edit mode #5952
Comments
Hey @adharshmk96, thanks for raising this! |
This happens because the checkbox also fires a diff --git a/packages/grid/x-data-grid/src/hooks/features/focus/useGridFocus.ts b/packages/grid/x-data-grid/src/hooks/features/focus/useGridFocus.ts
index b37f7e1cc..8b697e802 100644
--- a/packages/grid/x-data-grid/src/hooks/features/focus/useGridFocus.ts
+++ b/packages/grid/x-data-grid/src/hooks/features/focus/useGridFocus.ts
@@ -33,6 +33,7 @@ export const useGridFocus = (
const logger = useGridLogger(apiRef, 'useGridFocus');
const lastClickedCell = React.useRef<GridCellParams | null>(null);
+ const ignoreClickEvent = React.useRef<boolean>(true);
const setCellFocus = React.useCallback<GridFocusApi['setCellFocus']>(
(id, field) => {
@@ -184,8 +185,17 @@ export const useGridFocus = (
lastClickedCell.current = params;
}, []);
+ const handleDocumentMouseDown = React.useCallback(() => {
+ ignoreClickEvent.current = false;
+ }, []);
+
const handleDocumentClick = React.useCallback(
(event: MouseEvent) => {
+ if (ignoreClickEvent.current) {
+ return;
+ }
+ ignoreClickEvent.current = true;
+
const cellParams = lastClickedCell.current;
lastClickedCell.current = null;
@@ -271,11 +281,13 @@ export const useGridFocus = (
React.useEffect(() => {
const doc = ownerDocument(apiRef.current.rootElementRef!.current);
doc.addEventListener('click', handleDocumentClick);
+ doc.addEventListener('mousedown', handleDocumentMouseDown);
return () => {
doc.removeEventListener('click', handleDocumentClick);
+ doc.removeEventListener('mousedown', handleDocumentMouseDown);
};
- }, [apiRef, handleDocumentClick]);
+ }, [apiRef, handleDocumentClick, handleDocumentMouseDown]);
useGridApiEventHandler(apiRef, 'columnHeaderBlur', handleBlur);
useGridApiEventHandler(apiRef, 'cellDoubleClick', handleCellDoubleClick); |
@m4theushw I have figured it out the problem is const handleCellKeyDown = React.useCallback<GridEventListener<'cellKeyDown'>>(
(params, event) => {
// GRID_CELL_NAVIGATION_KEY_DOWN handles the focus on Enter, Tab and navigation keys
if (event.key === 'Enter' || event.key === 'Tab' || isNavigationKey(event.key)) {
return;
}
apiRef.current.setCellFocus(params.id, params.field);
},
[apiRef],
);
|
const handleCellKeyDown = React.useCallback<GridEventListener<'cellKeyDown'>>(
(params, event) => {
if (cellParams.cellMode !== GridCellModes.Edit && isNavigationKey(event.key)) {
apiRef.current.publishEvent('cellNavigationKeyDown', cellParams, event);
}
},
[apiRef],
); |
Issue is no longer reproducable on latest version. 💪🏼 |
How did we do @adharshmk96? |
Order ID 💳
45398
Duplicates
Latest version
The problem in depth 🔍
I have a problem with checkbox in row edit mode.
In the example here, https://codesandbox.io/s/updaterowsapiref-demo-mui-x-forked-buy7rq?file=/demo.tsx
current behaviour
If I highlight a cell in age column, press enter ( to enter edit mode ), press tab ( to reach checkbox ), pressing space or enter to change the checkbox value is exiting the edit mode
expected behaviour
pressing space to change the checkbox value should not exit the row edit mode
how can I achieve this
PS: if you highlight checkbox and press enter to enter the edit mode, you can toggle using space without exiting edit mode.
Your environment 🌎
`npx @mui/envinfo`
The text was updated successfully, but these errors were encountered: