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] Fix "stop editing" integration with IME e.g. Japanese #5257

Merged

Conversation

Gumichocopengin8
Copy link
Contributor

@Gumichocopengin8 Gumichocopengin8 commented Jun 19, 2022

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.

@Gumichocopengin8 Gumichocopengin8 changed the title [fix] IME support for some Asian languages [GridCellEdit] IME fix for some Asian languages Jun 19, 2022
@oliviertassinari
Copy link
Member

@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 oliviertassinari added bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! feature: Editing Related to the data grid Editing feature labels Jun 19, 2022
@Gumichocopengin8
Copy link
Contributor Author

@oliviertassinari which files should I write tests in?

@m4theushw m4theushw self-requested a review June 20, 2022 13:21
@m4theushw m4theushw changed the title [GridCellEdit] IME fix for some Asian languages [DataGrid] IME fix for some Asian languages Jun 20, 2022
@m4theushw
Copy link
Member

You can add the test in

describe('by pressing a printable character', () => {
it(`should publish 'cellEditStart' with reason=printableKeyDown`, () => {

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.

describe('by pressing a printable character', () => {
it(`should publish 'rowEditStart' with reason=printableKeyDown`, () => {

@Gumichocopengin8
Copy link
Contributor Author

@m4theushw thank you for the information.


I added test cases.

@Gumichocopengin8
Copy link
Contributor Author

@oliviertassinari @m4theushw Could you please review this PR? Thanks!

@m4theushw
Copy link
Member

@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.

Copy link
Member

@cherniavskii cherniavskii left a 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) {
Copy link
Member

@cherniavskii cherniavskii Jun 25, 2022

Choose a reason for hiding this comment

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

@Gumichocopengin8
Copy link
Contributor Author

@cherniavskii Thanks for reviewing.
I believe that Japanese people usually use space key to change the word instead of tab key. That's why I just applied the change only for enter. Do you still want the change for tab?

@oliviertassinari
Copy link
Member

oliviertassinari commented Jun 25, 2022

Do you still want the change for tab?

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 event.key if event.which === 229, so Tab included. I don't think that we can predict how IME assistant works on all the platforms/browsers. On macOS, Tab support seems to be required to change tabs, same goes for Shift+Tab.

Screen.Recording.2022-06-25.at.12.22.04.mov

It'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.

@oliviertassinari oliviertassinari changed the title [DataGrid] IME fix for some Asian languages [DataGrid] Fix "stop editing" integration with IME e.g. Japanese Jun 25, 2022
@Gumichocopengin8
Copy link
Contributor Author

added a new commit to handle tab key. Also, edited implementation in useGridCellEditing.old.ts and added a test case for it.

@Gumichocopengin8
Copy link
Contributor Author

@m4theushw @cherniavskii Could you review this again, please?

@mui-bot
Copy link

mui-bot commented Jun 30, 2022

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 284.8 667.5 469.5 450.12 146.147
Sort 100k rows ms 512.3 1,051.7 512.3 865.4 195.452
Select 100k rows ms 141.3 261.3 224.6 215.78 41.723
Deselect 100k rows ms 153.4 378 191.5 241.4 88.957

Generated by 🚫 dangerJS against 052373f

Copy link
Member

@m4theushw m4theushw left a 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?

Copy link
Member

@cherniavskii cherniavskii left a 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.

@Gumichocopengin8
Copy link
Contributor Author

@cherniavskii

@Gumichocopengin8 Are you OK with licensing your changes to the test files under MIT license?
We are going to update our license to cover all test files in the repo by MIT license.

Yes, I'm ok with it. Thank you for reviewing!

@cherniavskii cherniavskii merged commit 22567ed into mui:master Jul 5, 2022
@Gumichocopengin8 Gumichocopengin8 deleted the fix/IME-support-for-asian-lang branch July 5, 2022 13:34
cherniavskii pushed a commit to cherniavskii/mui-x that referenced this pull request Jul 6, 2022
…#5257)

Co-authored-by: Matheus Wichman <matheushw@outlook.com>
joserodolfofreitas pushed a commit to joserodolfofreitas/mui-x that referenced this pull request Jul 15, 2022
…#5257)

Co-authored-by: Matheus Wichman <matheushw@outlook.com>
alexfauquette pushed a commit to alexfauquette/mui-x that referenced this pull request Aug 26, 2022
…#5257)

Co-authored-by: Matheus Wichman <matheushw@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! feature: Editing Related to the data grid Editing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[data grid] Broken "stop editing" integration with IME e.g. Japanese
5 participants