Skip to content

Commit

Permalink
[data-grid]: use event.type for detecting IME key press (#14146)
Browse files Browse the repository at this point in the history
  • Loading branch information
k-rajat19 authored Oct 1, 2024
1 parent 8edc40a commit 24c0442
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,13 @@ describe('<DataGridPro /> - Cell editing', () => {
fireEvent.doubleClick(cell);
const input = cell.querySelector('input')!;
fireEvent.change(input, { target: { value: 'あ' } });
fireEvent.keyDown(cell, { key: 'Enter', keyCode: 229 });
fireEvent.keyDown(cell, {
type: 'compositionstart',
isComposing: true,
charCode: 'あ'.charCodeAt(0),
bubbles: true,
cancelable: true,
});
expect(listener.callCount).to.equal(0);
fireEvent.keyDown(cell, { key: 'Enter', keyCode: 13 });
expect(listener.callCount).to.equal(1);
Expand All @@ -974,7 +980,22 @@ describe('<DataGridPro /> - Cell editing', () => {
fireEvent.doubleClick(cell);
const input = cell.querySelector('input')!;
fireEvent.change(input, { target: { value: 'ありがとう' } });
fireEvent.keyDown(cell, { key: 'Enter', keyCode: 229 });

fireEvent.keyDown(cell, {
type: 'compositionstart',
isComposing: true,
charCode: 'あ'.charCodeAt(0),
bubbles: true,
cancelable: true,
});
fireEvent.keyDown(cell, {
type: 'compositionupdate',
isComposing: true,
charCode: 'う'.charCodeAt(0),
bubbles: true,
cancelable: true,
});

expect(listener.callCount).to.equal(0);
fireEvent.keyDown(cell, { key: 'Enter', keyCode: 13 });
expect(listener.callCount).to.equal(1);
Expand Down
23 changes: 21 additions & 2 deletions packages/x-data-grid-pro/src/tests/rowEditing.DataGridPro.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,13 @@ describe('<DataGridPro /> - Row editing', () => {
fireEvent.doubleClick(cell);
const input = cell.querySelector('input')!;
fireEvent.change(input, { target: { value: 'あ' } });
fireEvent.keyDown(input, { key: 'Enter', keyCode: 229 });
fireEvent.keyDown(input, {
type: 'compositionstart',
isComposing: true,
charCode: 'あ'.charCodeAt(0),
bubbles: true,
cancelable: true,
});
expect(listener.callCount).to.equal(0);
fireEvent.keyDown(input, { key: 'Enter', keyCode: 13 });
expect(listener.callCount).to.equal(1);
Expand All @@ -947,7 +953,20 @@ describe('<DataGridPro /> - Row editing', () => {
fireEvent.doubleClick(cell);
const input = cell.querySelector('input')!;
fireEvent.change(input, { target: { value: 'ありがとう' } });
fireEvent.keyDown(input, { key: 'Enter', keyCode: 229 });
fireEvent.keyDown(input, {
type: 'compositionstart',
isComposing: true,
charCode: 'あ'.charCodeAt(0),
bubbles: true,
cancelable: true,
});
fireEvent.keyDown(input, {
type: 'compositionupdate',
isComposing: true,
charCode: 'う'.charCodeAt(0),
bubbles: true,
cancelable: true,
});
expect(listener.callCount).to.equal(0);
fireEvent.keyDown(input, { key: 'Enter', keyCode: 13 });
expect(listener.callCount).to.equal(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ export const useGridCellEditing = (
(params, event) => {
if (params.cellMode === GridCellModes.Edit) {
// Wait until IME is settled for Asian languages like Japanese and Chinese
// TODO: `event.which` is deprecated but this is a temporary workaround
if (event.which === 229) {
if (event.type === 'compositionstart' || event.type === 'compositionupdate') {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ export const useGridRowEditing = (
(params, event) => {
if (params.cellMode === GridRowModes.Edit) {
// Wait until IME is settled for Asian languages like Japanese and Chinese
// TODO: `event.which` is deprecated but this is a temporary workaround
if (event.which === 229) {
if (event.type === 'compositionstart' || event.type === 'compositionupdate') {
return;
}

Expand Down

0 comments on commit 24c0442

Please sign in to comment.