Skip to content

Commit

Permalink
TabbableContainer: fix bug where pressing tab in browser environments…
Browse files Browse the repository at this point in the history
… would move the focus by two tabbable elements (instead of one)
  • Loading branch information
ciampo committed Aug 31, 2022
1 parent 8b72831 commit 5cbbc56
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/components/src/navigable-container/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,14 @@ class NavigableContainer extends Component {
// 'handling' the event, as voiceover will try to use arrow keys
// for highlighting text.
const targetRole = event.target.getAttribute( 'role' );
if ( MENU_ITEM_ROLES.includes( targetRole ) ) {
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 ) {
event.preventDefault();
}
}
Expand Down

0 comments on commit 5cbbc56

Please sign in to comment.