Skip to content

Commit

Permalink
Handle edge cases in with-constrained-tabbing.
Browse files Browse the repository at this point in the history
  • Loading branch information
afercia committed Sep 25, 2018
1 parent 6321a99 commit 4d21ead
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ const withConstrainedTabbing = createHigherOrderComponent(
} else if ( ! event.shiftKey && event.target === lastTabbable ) {
event.preventDefault();
firstTabbable.focus();
/*
* When pressing Tab and none of the tabbables has focus, the keydown
* event happens on the wrapper div: move focus on the first tabbable.
*/
} else if ( ! tabbables.includes( event.target ) ) {
event.preventDefault();
firstTabbable.focus();
}
}

Expand All @@ -44,6 +51,7 @@ const withConstrainedTabbing = createHigherOrderComponent(
<div
onKeyDown={ this.handleTabBehaviour }
ref={ this.focusContainRef }
tabIndex="-1"
>
<WrappedComponent { ...this.props } />
</div>
Expand Down

0 comments on commit 4d21ead

Please sign in to comment.