Skip to content

Commit

Permalink
UnitControl: Fix an issue where keyboard shortcuts unintentionally sh…
Browse files Browse the repository at this point in the history
…ift focus on Windows OS (#62988)

* UnitControl: Fix an issue where keyboard shortcuts unintentionally shift focus on Windows OS

* Update changelog

* Update comment

Unlinked contributors: webexpr-dhenriet.

Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
  • Loading branch information
3 people authored Jul 2, 2024
1 parent 0090d4e commit a19348b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- `UnitControl`: Fix colors when disabled. ([#62970](https://github.com/WordPress/gutenberg/pull/62970))
- `useUpdateEffect`: Correctly track mounted state in strict mode. ([#62974](https://github.com/WordPress/gutenberg/pull/62974))
- `UnitControl`: Fix an issue where keyboard shortcuts unintentionally shift focus on Windows OS. ([#62988](https://github.com/WordPress/gutenberg/pull/62988))

### Internal

Expand Down
5 changes: 3 additions & 2 deletions packages/components/src/unit-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,12 @@ function UnforwardedUnitControl(
if ( ! disableUnits && isUnitSelectTabbable && units.length ) {
handleOnKeyDown = ( event: KeyboardEvent< HTMLInputElement > ) => {
props.onKeyDown?.( event );
// Unless the meta key was pressed (to avoid interfering with
// shortcuts, e.g. pastes), moves focus to the unit select if a key
// Unless the meta or ctrl key was pressed (to avoid interfering with
// shortcuts, e.g. pastes), move focus to the unit select if a key
// matches the first character of a unit.
if (
! event.metaKey &&
! event.ctrlKey &&
reFirstCharacterOfUnits.test( event.key )
) {
refInputSuffix.current?.focus();
Expand Down

0 comments on commit a19348b

Please sign in to comment.