Skip to content

Commit

Permalink
PreventDefault when isComposing is true. apply patch from t-hamano. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
torounit authored and ramonjd committed Jul 28, 2023
1 parent 2912e1b commit 8142681
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/commands/src/components/command-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,20 @@ export function CommandMenu() {
if ( ! isOpen ) {
return false;
}

const onKeyDown = ( event ) => {
if (
// Ignore keydowns from IMEs
event.nativeEvent.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
) {
event.preventDefault();
}
};

const isLoading = Object.values( loaders ).some( Boolean );

return (
Expand All @@ -211,7 +225,10 @@ export function CommandMenu() {
__experimentalHideHeader
>
<div className="commands-command-menu__container">
<Command label={ __( 'Command palette' ) }>
<Command
label={ __( 'Command palette' ) }
onKeyDown={ onKeyDown }
>
<div className="commands-command-menu__header">
<Command.Input
ref={ commandMenuInput }
Expand Down

0 comments on commit 8142681

Please sign in to comment.