Skip to content

Commit 700a28a

Browse files
jasonblancharddiasbruno
authored andcommitted
[fixed] Tab focus escapes modal on shift + tab after opening
1 parent d93fae1 commit 700a28a

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

specs/Modal.events.spec.js

+15
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@ export default () => {
4444
document.activeElement.should.be.eql(content);
4545
});
4646

47+
it("Traps tab in the modal one shift + tab", () => {
48+
const topButton = <button>top</button>;
49+
const bottomButton = <button>bottom</button>;
50+
const modalContent = (
51+
<div>
52+
{topButton}
53+
{bottomButton}
54+
</div>
55+
);
56+
const modal = renderModal({ isOpen: true }, modalContent);
57+
const content = mcontent(modal);
58+
tabKeyDown(content, { shiftKey: true });
59+
document.activeElement.textContent.should.be.eql("bottom");
60+
});
61+
4762
describe("shouldCloseOnEsc", () => {
4863
context("when true", () => {
4964
it("should close on Esc key event", () => {

src/helpers/scopeTab.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ export default function scopeTab(node, event) {
1313
const head = tabbable[0];
1414
const tail = tabbable[tabbable.length - 1];
1515

16-
// proceed with default browser behavior
16+
// proceed with default browser behavior on tab.
17+
// Focus on last element on shift + tab.
1718
if (node === document.activeElement) {
18-
return;
19+
if (!shiftKey) return;
20+
target = tail;
1921
}
2022

2123
var target;

0 commit comments

Comments
 (0)