From d56f49eb723cdb8117d8f51a8160db5c60aed5cb Mon Sep 17 00:00:00 2001 From: Anton Korzunov Date: Sun, 7 Nov 2021 17:42:48 +1100 Subject: [PATCH] fix: do not use capture phase for focus-in events, fixes #134 --- _tests/FocusLock.spec.js | 4 ++++ src/Trap.js | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/_tests/FocusLock.spec.js b/_tests/FocusLock.spec.js index 3fb3a13..99fc46d 100644 --- a/_tests/FocusLock.spec.js +++ b/_tests/FocusLock.spec.js @@ -835,6 +835,7 @@ text )} ); + // will be never focused at React 17 sinon.assert.calledOnce(focusSpy); setTimeout(() => { expect(document.activeElement.innerHTML).to.be.equal('button-action'); @@ -864,6 +865,7 @@ text ); + // setTimeout(() => { // React 17 document.getElementById('portaled2').focus(); expect(document.activeElement.innerHTML).to.be.equal('i am portaled'); setTimeout(() => { @@ -899,11 +901,13 @@ text ); + // setTimeout(() => { // React 17 expect(document.activeElement.innerHTML).to.be.equal('i am portaled'); setTimeout(() => { expect(document.activeElement.innerHTML).to.be.equal('i am portaled'); done(); }, 1); + // },16); }); }); diff --git a/src/Trap.js b/src/Trap.js index 8ec1671..10c021a 100644 --- a/src/Trap.js +++ b/src/Trap.js @@ -171,13 +171,13 @@ const onWindowBlur = () => { }; const attachHandler = () => { - document.addEventListener('focusin', onTrap, true); + document.addEventListener('focusin', onTrap); document.addEventListener('focusout', onBlur); window.addEventListener('blur', onWindowBlur); }; const detachHandler = () => { - document.removeEventListener('focusin', onTrap, true); + document.removeEventListener('focusin', onTrap); document.removeEventListener('focusout', onBlur); window.removeEventListener('blur', onWindowBlur); };