Skip to content

Commit 6dcc20b

Browse files
author
Scott Robertson
committed
[fixed] stacked/nested modals have focus lost in Safari
Fixes #801 If the `keydown` event within the currently-open, nested modal is propagated, Safari will toggle focus between the parent modal's focusable elements instead.
1 parent 68af7ec commit 6dcc20b

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

specs/Modal.events.spec.js

+24
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,30 @@ export default () => {
109109
});
110110
});
111111

112+
it("shifts focus within nested modals", () => {
113+
withElementCollector(() => {
114+
let nestedModal;
115+
const props = { isOpen: true };
116+
const node = createHTMLElement("div");
117+
118+
ReactDOM.render(
119+
<Modal {...props} appElement={node}>
120+
<button>Outer Button 1</button>
121+
<button>Outer Button 2</button>
122+
<Modal ref={el => (nestedModal = el)} appElement={node} a isOpen>
123+
<button id="foo">Button One</button>
124+
<button id="bar">Button Two</button>
125+
</Modal>
126+
</Modal>,
127+
node
128+
);
129+
const content = mcontent(nestedModal);
130+
tabKeyDown(content, { shiftKey: true });
131+
document.activeElement.textContent.should.be.eql("Button Two");
132+
ReactDOM.unmountComponentAtNode(node);
133+
});
134+
});
135+
112136
describe("shouldCloseOnEsc", () => {
113137
context("when true", () => {
114138
it("should close on Esc key event", () => {

src/components/ModalPortal.js

+1
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ export default class ModalPortal extends Component {
275275

276276
handleKeyDown = event => {
277277
if (event.keyCode === TAB_KEY) {
278+
event.stopPropagation();
278279
scopeTab(this.content, event);
279280
}
280281

0 commit comments

Comments
 (0)