Skip to content

Commit

Permalink
fix: do not use capture phase for focus-in events, fixes #134
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Nov 7, 2021
1 parent f28f15f commit d56f49e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions _tests/FocusLock.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ text
)}
</div>
</div>);
// will be never focused at React 17
sinon.assert.calledOnce(focusSpy);
setTimeout(() => {
expect(document.activeElement.innerHTML).to.be.equal('button-action');
Expand Down Expand Up @@ -864,6 +865,7 @@ text
<button>6-action4</button>
</FocusLock>
</div>);
// setTimeout(() => { // React 17
document.getElementById('portaled2').focus();
expect(document.activeElement.innerHTML).to.be.equal('i am portaled');
setTimeout(() => {
Expand Down Expand Up @@ -899,11 +901,13 @@ text
<button>6-action4</button>
</FocusLock>
</div>);
// 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);
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/Trap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down

0 comments on commit d56f49e

Please sign in to comment.