-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[DataGrid] Fix "stop editing" integration with IME e.g. Japanese #5257
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] Fix "stop editing" integration with IME e.g. Japanese #5257
Conversation
@Gumichocopengin8 Thanks for working on this problem. First, we would need to add a new test case. The test cases in mui/material-ui#23050 and mui/material-ui#19499 could help. |
@oliviertassinari which files should I write tests in? |
You can add the test in mui-x/packages/grid/x-data-grid-pro/src/tests/cellEditing.DataGridPro.new.test.tsx Lines 669 to 670 in 03855a9
The fix you proposed should also be added to the row editing in https://github.com/mui/mui-x/blob/master/packages/grid/x-data-grid/src/hooks/features/editRows/useGridRowEditing.new.ts Then we have a file only for tests with row editing, which has the same structure from the cell editing. You can almost just duplicate the new test. mui-x/packages/grid/x-data-grid-pro/src/tests/rowEditing.DataGridPro.new.test.tsx Lines 681 to 682 in 03855a9
|
@m4theushw thank you for the information. I added test cases. |
@oliviertassinari @m4theushw Could you please review this PR? Thanks! |
@cherniavskii @DanailH could you test the fix on macOS? The shortcut to trigger the IME is different on Windows. I'm good with the tests added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
It works on macOS with Enter, but I would suggest to handle Tab key as well, since it can be used in IME on MacOS as well:
diff --git a/packages/grid/x-data-grid/src/hooks/features/e
ditRows/useGridCellEditing.new.ts b/packages/grid/x-data-gr
id/src/hooks/features/editRows/useGridCellEditing.new.ts
index 00519a0938..5357c34da9 100644
--- a/packages/grid/x-data-grid/src/hooks/features/editRows
/useGridCellEditing.new.ts
+++ b/packages/grid/x-data-grid/src/hooks/features/editRows
/useGridCellEditing.new.ts
@@ -137,6 +137,9 @@ export const useGridCellEditing = (
}
reason = GridCellEditStopReasons.enterKeyDown;
} else if (event.key === 'Tab') {
+ if (event.which === 229) {
+ return;
+ }
reason = event.shiftKey
? GridCellEditStopReasons.shiftTabKeyDown
: GridCellEditStopReasons.tabKeyDown;
diff --git a/packages/grid/x-data-grid/src/hooks/features/e
ditRows/useGridRowEditing.new.ts b/packages/grid/x-data-gri
d/src/hooks/features/editRows/useGridRowEditing.new.ts
index 4514805788..7fcc203619 100644
--- a/packages/grid/x-data-grid/src/hooks/features/editRows
/useGridRowEditing.new.ts
+++ b/packages/grid/x-data-grid/src/hooks/features/editRows/useGridRowEditing.new.ts
@@ -179,6 +179,9 @@ export const useGridRowEditing = (
}
reason = GridRowEditStopReasons.enterKeyDown;
} else if (event.key === 'Tab') {
+ if (event.which === 229) {
+ return;
+ }
const columnFields = gridColumnFieldsSelector(apiRef).filter((field) =>
apiRef.current.isCellEditable(apiRef.current.getCellParams(params.id, field)),
);
Here's how it works with the changes above applied
Screen.Recording.2022-06-25.at.08.28.41.mov
@@ -130,6 +130,11 @@ export const useGridCellEditing = ( | |||
if (event.key === 'Escape') { | |||
reason = GridCellEditStopReasons.escapeKeyDown; | |||
} else if (event.key === 'Enter') { | |||
// Wait until IME is settled for Asian languages like Japanese and Chinese | |||
// TODO: `event.which` is depricated but this is a temporary workaround | |||
if (event.which === 229) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do this for old editing implementation as well, since it's an easy change: https://github.com/mui/mui-x/blob/master/packages/grid/x-data-grid/src/hooks/features/editRows/useGridCellEditing.old.ts
@cherniavskii Thanks for reviewing. |
Agree with @cherniavskii; it's what mui/material-ui#23044 was exactly about after only handling Enter in mui/material-ui#19435. From my perspective, we should filter ALL key events, regardless of the value of Screen.Recording.2022-06-25.at.12.22.04.movIt's what select2 does https://github.com/select2/select2/pull/2483/files#diff-1fb8e09d75683cc4dd4a88850714595fR2105. Otherwise, we can copy Ant Design and go with, keeping track of the composite events: https://github.com/react-component/select/pull/505/files. |
added a new commit to handle tab key. Also, edited implementation in |
packages/grid/x-data-grid/src/hooks/features/editRows/useGridCellEditing.new.ts
Outdated
Show resolved
Hide resolved
f7a8ea8
to
879338e
Compare
@m4theushw @cherniavskii Could you review this again, please? |
These are the results for the performance tests:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with the tests added. @cherniavskii could you test on macOS if the fix works in both new and old editing APIs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works with both old and new editing APIs.
Thank you @Gumichocopengin8, great work! 🎉
@Gumichocopengin8 Are you OK with licensing your changes to the test files under MIT license?
We are going to update our license in the repository to make all our test files MIT licensed. Currently, some of the tests files have a commercial license.
Yes, I'm ok with it. Thank you for reviewing! |
…#5257) Co-authored-by: Matheus Wichman <matheushw@outlook.com>
…#5257) Co-authored-by: Matheus Wichman <matheushw@outlook.com>
…#5257) Co-authored-by: Matheus Wichman <matheushw@outlook.com>
https://deploy-preview-5257--material-ui-x.netlify.app/x/react-data-grid/editing/#making-a-column-editable
Close #2338
I used
event.which
to fix this issue because it seems like it is the best way for now. However, it is deprecated. In the future, need to find alternatives.