Skip to content

[data grid] Start edit mode with text typed without a composition - #24098

Open
costajohnt wants to merge 1 commit into
mui:masterfrom
costajohnt:fix/data-grid-ime-text-without-composition
Open

costajohnt wants to merge 1 commit into
mui:masterfrom
costajohnt:fix/data-grid-ime-text-without-composition

Conversation

@costajohnt

Copy link
Copy Markdown
Contributor

Fixes #24063

With experimentalFeatures.imeFastEdit, typed text that arrives without a composition (emoji picker, dictation, an IME that commits a character directly) reached the hidden editor and was lost, because the keydown waits for compositionstart and handleChange ignored view-mode input.

Now an input event in view mode publishes an internal cellInput event. Both editing hooks treat it like a composition start, with the printableKeyDown reason, so code that already blocks that reason also blocks these inserts. The editor then waits a microtask for the edit state and applies the text through the normal setEditCellValue path, so valueParser and preProcessEditCellProps still run.

Keeping this from reopening other holes took most of the diff:

  • Only inputType === 'insertText' starts edit mode. Paste, drop, undo and composition input keep today's behavior of being dropped, so unknown input types fail the same way master does.
  • Vetoes stay final. A keydown veto doesn't call preventDefault, so the browser still inserted the character, which would now start edit mode. GridCell prevents the default after publishing cellKeyDown when a printable key was vetoed in the hidden editor, and the same happens when canStartEditing refuses (Shift+Space with cellSelection and rowSelection={false} replaced the cell value otherwise).
  • Types and docs. cellEditStart and rowEditStart events can now be a ChangeEvent, with params.key undefined. That is what changes the generated API files and proptypes. editing.md lists the new limits.

Limits worth a look

  • A controlled cellModesModel or rowModesModel applied later than the microtask loses the text, and one keystroke can call the edit start callback twice. Documented rather than handled, since this is an experimental flag. Holding the text in a ref until the mode changes would remove it if you prefer that.
  • onCellKeyDown can't stop IME text, only onCellEditStart can. Documented.
  • With an async preProcessEditCellProps, the start validation and the text validation now overlap, because the text skips the debounce. The race already exists for validators slower than 200 ms, so I left it.
  • The Ctrl+Shift+Space guard is defensive and has no test. Neither user-event nor Playwright on Linux inserts a character for it.

Testing

Regression tests fail on master and cover cell and row mode, vetoes, the allowlist, controlled models and non-editable cells. imeFastEdit tests pass in jsdom and in Chromium (test:browser: 174 passed in x-data-grid, 37 in x-data-grid-pro).

In Chromium 156, CDP Input.insertText gives inputType: 'insertText' with isComposing: false, and Input.imeSetComposition gives insertCompositionText with isComposing: true. I have not tested a real IME, the emoji picker or dictation, and inputType for dictation on Safari and Firefox is unverified. If one reports something else, it is dropped as on master and the allowlist would need that value.

With `imeFastEdit`, text from the emoji picker, dictation or an IME that
commits directly reached the hidden editor and was lost. An `input` event
with `inputType` `insertText` in view mode now starts edit mode and keeps
the text. Keydown vetoes stay final, and pasted or dropped text is still
ignored.

Fixes mui#24063
@code-infra-dashboard

Copy link
Copy Markdown

Deploy preview

Bundle size

Bundle Parsed size Gzip size
@mui/x-data-grid 🔺+676B(+0.16%) 🔺+203B(+0.16%)
@mui/x-data-grid-pro 🔺+647B(+0.11%) 🔺+230B(+0.14%)
@mui/x-data-grid-premium 🔺+675B(+0.09%) 🔺+208B(+0.09%)
@mui/x-charts 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) 0B(0.00%)
@mui/x-charts-premium 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 0B(0.00%)
@mui/x-scheduler 0B(0.00%) 0B(0.00%)
@mui/x-scheduler-premium 0B(0.00%) 0B(0.00%)
@mui/x-chat 0B(0.00%) 0B(0.00%)
@mui/x-license 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[data grid] imeFastEdit: text inserted without a composition is dropped

1 participant