Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 0ff1b34

Browse files
authored
Merge pull request #160 from ckeditor/t/159
Fix: `FocusTracker` should remain in sync when multiple 'blur' events are followed by the 'focus'. Closes #159.
2 parents 2f58a92 + 5a42e99 commit 0ff1b34

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/focustracker.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ export default class FocusTracker {
115115
* @fires blur
116116
*/
117117
_blur() {
118+
clearTimeout( this._nextEventLoopTimeout );
119+
118120
this._nextEventLoopTimeout = setTimeout( () => {
119121
this.focusedElement = null;
120122
this.isFocused = false;

tests/focustracker.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,19 @@ describe( 'FocusTracker', () => {
115115
expect( focusTracker.isFocused ).to.true;
116116
expect( changeSpy.notCalled ).to.true;
117117
} );
118+
119+
// https://github.com/ckeditor/ckeditor5-utils/issues/159
120+
it( 'should keep `isFocused` synced when multiple blur events are followed by the focus', () => {
121+
focusTracker.add( container );
122+
focusTracker.isFocused = true;
123+
124+
container.dispatchEvent( new Event( 'blur' ) );
125+
containerFirstInput.dispatchEvent( new Event( 'blur' ) );
126+
containerSecondInput.dispatchEvent( new Event( 'focus' ) );
127+
testUtils.sinon.clock.tick( 0 );
128+
129+
expect( focusTracker.isFocused ).to.be.true;
130+
} );
118131
} );
119132
} );
120133

0 commit comments

Comments
 (0)