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

Commit

Permalink
Fix: FocusTracker should remain in sync when multiple 'blur' events a…
Browse files Browse the repository at this point in the history
…re followed by the 'focus'. Closes #159.
  • Loading branch information
oleq committed May 23, 2017
1 parent 2f58a92 commit 5a42e99
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/focustracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ export default class FocusTracker {
* @fires blur
*/
_blur() {
clearTimeout( this._nextEventLoopTimeout );

this._nextEventLoopTimeout = setTimeout( () => {
this.focusedElement = null;
this.isFocused = false;
Expand Down
13 changes: 13 additions & 0 deletions tests/focustracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ describe( 'FocusTracker', () => {
expect( focusTracker.isFocused ).to.true;
expect( changeSpy.notCalled ).to.true;
} );

// https://github.com/ckeditor/ckeditor5-utils/issues/159
it( 'should keep `isFocused` synced when multiple blur events are followed by the focus', () => {
focusTracker.add( container );
focusTracker.isFocused = true;

container.dispatchEvent( new Event( 'blur' ) );
containerFirstInput.dispatchEvent( new Event( 'blur' ) );
containerSecondInput.dispatchEvent( new Event( 'focus' ) );
testUtils.sinon.clock.tick( 0 );

expect( focusTracker.isFocused ).to.be.true;
} );
} );
} );

Expand Down

0 comments on commit 5a42e99

Please sign in to comment.