Skip to content

Commit

Permalink
[TrapFocus] Don't contain if document isn't focused
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Apr 22, 2020
1 parent b7bcfd3 commit 029d2a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/material-ui/src/Modal/Modal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,12 @@ describe('<Modal />', () => {
clock.restore();
});

it('contains the focus if the active element is removed', () => {
it('contains the focus if the active element is removed', function test() {
if (/jsdom/.test(window.navigator.userAgent)) {
// see https://github.com/jsdom/jsdom/issues/2953
this.skip();
}

function WithRemovableElement({ hideButton = false }) {
return (
<Modal open>
Expand Down
7 changes: 6 additions & 1 deletion packages/material-ui/src/Modal/TrapFocus.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ function TrapFocus(props) {
}

const contain = () => {
if (disableEnforceFocus || !isEnabled() || ignoreNextEnforceFocus.current) {
if (
!doc.hasFocus() ||
disableEnforceFocus ||
!isEnabled() ||
ignoreNextEnforceFocus.current
) {
ignoreNextEnforceFocus.current = false;
return;
}
Expand Down

0 comments on commit 029d2a2

Please sign in to comment.