Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Bug Fix

- `FormTokenField`: Fix duplicate input in IME composition ([#45607](https://github.com/WordPress/gutenberg/pull/45607)).
- `Autocomplete`: Fix unexpected block insertion during IME composition ([#45510](https://github.com/WordPress/gutenberg/pull/45510)).

### Internal
Expand Down
18 changes: 13 additions & 5 deletions packages/components/src/form-token-field/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,18 @@ export function FormTokenField( props: FormTokenFieldProps ) {
function onKeyDown( event: KeyboardEvent ) {
let preventDefault = false;

if ( event.defaultPrevented ) {
if (
event.defaultPrevented ||
// 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
) {
return;
}
switch ( event.code ) {
switch ( event.key ) {
case 'Backspace':
preventDefault = handleDeleteKey( deleteTokenBeforeInput );
break;
Expand Down Expand Up @@ -213,9 +221,9 @@ export function FormTokenField( props: FormTokenFieldProps ) {

function onKeyPress( event: KeyboardEvent ) {
let preventDefault = false;
// TODO: replace to event.code;
switch ( event.charCode ) {
case 44: // Comma.

switch ( event.key ) {
case ',':
preventDefault = handleCommaKey();
break;
default:
Expand Down