-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Components: Add HOF to ignore IME keydowns (#59081)
* Components: Add HOF to ignore IME keydowns * Replace usages * Update changelog * Clean up Co-authored-by: mirka <[email protected]> Co-authored-by: t-hamano <[email protected]> Co-authored-by: tyxla <[email protected]>
- Loading branch information
1 parent
467aade
commit 280c5d7
Showing
6 changed files
with
74 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* A higher-order function that wraps a keydown event handler to ensure it is not an IME event. | ||
* | ||
* In CJK languages, an IME (Input Method Editor) is used to input complex characters. | ||
* During an IME composition, keydown events (e.g. Enter or Escape) can be fired | ||
* which are intended to control the IME and not the application. | ||
* These events should be ignored by any application logic. | ||
* | ||
* @param keydownHandler The keydown event handler to execute after ensuring it was not an IME event. | ||
* | ||
* @return A wrapped version of the given event handler that ignores IME events. | ||
*/ | ||
export function withIgnoreIMEEvents< | ||
E extends React.KeyboardEvent | KeyboardEvent, | ||
>( keydownHandler: ( event: E ) => void ) { | ||
return ( event: E ) => { | ||
const { isComposing } = | ||
'nativeEvent' in event ? event.nativeEvent : event; | ||
|
||
if ( | ||
isComposing || | ||
// Workaround for Mac Safari where the final Enter/Backspace of an IME composition | ||
// is `isComposing=false`, even though it's technically still part of the composition. | ||
// These can only be detected by keyCode. | ||
event.keyCode === 229 | ||
) { | ||
return; | ||
} | ||
|
||
keydownHandler( event ); | ||
}; | ||
} |
280c5d7
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.
Flaky tests detected in 280c5d7.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7961353990
📝 Reported issues:
/test/e2e/specs/editor/blocks/navigation.spec.js