Skip to content

Commit

Permalink
Move isTab prevent default only when the component is actually hand…
Browse files Browse the repository at this point in the history
…ling the focus
  • Loading branch information
ciampo committed Apr 15, 2023
1 parent 7e0ebc3 commit 97e70ec
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/components/src/navigable-container/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,7 @@ class NavigableContainer extends Component {
const targetHasMenuItemRole =
MENU_ITEM_ROLES.includes( targetRole );

// `preventDefault()` on tab to avoid having the browser move the focus
// after this component has already moved it.
const isTab = event.code === 'Tab';

if ( targetHasMenuItemRole || isTab ) {
if ( targetHasMenuItemRole ) {
event.preventDefault();
}
}
Expand All @@ -126,9 +122,16 @@ class NavigableContainer extends Component {
const nextIndex = cycle
? cycleValue( index, focusables.length, offset )
: index + offset;

if ( nextIndex >= 0 && nextIndex < focusables.length ) {
focusables[ nextIndex ].focus();
onNavigate( nextIndex, focusables[ nextIndex ] );

// `preventDefault()` on tab to avoid having the browser move the focus
// after this component has already moved it.
if ( event.code === 'Tab' ) {
event.preventDefault();
}
}
}

Expand Down

0 comments on commit 97e70ec

Please sign in to comment.