From 6a50184ebe89a39b2e3ba016b5aef38886f08218 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Wed, 22 Apr 2020 15:53:55 +0200 Subject: [PATCH] [TrapFocus] Don't contain if document isn't focused --- packages/material-ui/src/Modal/Modal.test.js | 7 ++++++- packages/material-ui/src/Modal/TrapFocus.js | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/material-ui/src/Modal/Modal.test.js b/packages/material-ui/src/Modal/Modal.test.js index 201553586e5e51..c25d6e60696a31 100644 --- a/packages/material-ui/src/Modal/Modal.test.js +++ b/packages/material-ui/src/Modal/Modal.test.js @@ -548,7 +548,12 @@ describe('', () => { 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 ( diff --git a/packages/material-ui/src/Modal/TrapFocus.js b/packages/material-ui/src/Modal/TrapFocus.js index 1ce5d8afab5f6f..513072a488232d 100644 --- a/packages/material-ui/src/Modal/TrapFocus.js +++ b/packages/material-ui/src/Modal/TrapFocus.js @@ -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; }