8
0
Просмотр исходного кода

Fix: The clickOutsideHandler helper should use mousedown instead of mouseup event. Closes #281.

Aleksander Nowodzinski 8 лет назад
Родитель
Сommit
2ae3e7fe04

+ 1 - 1
packages/ckeditor5-ui/src/bindings/clickoutsidehandler.js

@@ -22,7 +22,7 @@
  * @param {Function} options.callback Function fired after clicking outside of specified elements.
  */
 export default function clickOutsideHandler( { emitter, activator, callback, contextElements } ) {
-	emitter.listenTo( document, 'mouseup', ( evt, { target } ) => {
+	emitter.listenTo( document, 'mousedown', ( evt, { target } ) => {
 		if ( !activator() ) {
 			return;
 		}

+ 7 - 7
packages/ckeditor5-ui/tests/bindings/clickoutsidehandler.js

@@ -41,7 +41,7 @@ describe( 'clickOutsideHandler', () => {
 	it( 'should fired callback after clicking out of context element when listener is active', () => {
 		activator.returns( true );
 
-		document.body.dispatchEvent( new Event( 'mouseup', { bubbles: true } ) );
+		document.body.dispatchEvent( new Event( 'mousedown', { bubbles: true } ) );
 
 		sinon.assert.calledOnce( actionSpy );
 	} );
@@ -49,7 +49,7 @@ describe( 'clickOutsideHandler', () => {
 	it( 'should not fired callback after clicking out of context element when listener is not active', () => {
 		activator.returns( false );
 
-		document.body.dispatchEvent( new Event( 'mouseup', { bubbles: true } ) );
+		document.body.dispatchEvent( new Event( 'mousedown', { bubbles: true } ) );
 
 		sinon.assert.notCalled( actionSpy );
 	} );
@@ -86,7 +86,7 @@ describe( 'clickOutsideHandler', () => {
 			callback: spy
 		} );
 
-		document.body.dispatchEvent( new Event( 'mouseup', { bubbles: true } ) );
+		document.body.dispatchEvent( new Event( 'mousedown', { bubbles: true } ) );
 
 		sinon.assert.calledOnce( spy );
 	} );
@@ -103,7 +103,7 @@ describe( 'clickOutsideHandler', () => {
 			callback: spy
 		} );
 
-		document.body.dispatchEvent( new Event( 'mouseup', { bubbles: true } ) );
+		document.body.dispatchEvent( new Event( 'mousedown', { bubbles: true } ) );
 
 		sinon.assert.notCalled( spy );
 	} );
@@ -111,20 +111,20 @@ describe( 'clickOutsideHandler', () => {
 	it( 'should react on model `ifActive` property change', () => {
 		activator.returns( true );
 
-		document.body.dispatchEvent( new Event( 'mouseup', { bubbles: true } ) );
+		document.body.dispatchEvent( new Event( 'mousedown', { bubbles: true } ) );
 
 		sinon.assert.calledOnce( actionSpy );
 
 		activator.returns( false );
 
-		document.body.dispatchEvent( new Event( 'mouseup', { bubbles: true } ) );
+		document.body.dispatchEvent( new Event( 'mousedown', { bubbles: true } ) );
 
 		// Still called once, was not called second time.
 		sinon.assert.calledOnce( actionSpy );
 
 		activator.returns( true );
 
-		document.body.dispatchEvent( new Event( 'mouseup', { bubbles: true } ) );
+		document.body.dispatchEvent( new Event( 'mousedown', { bubbles: true } ) );
 
 		// Called one more time.
 		sinon.assert.calledTwice( actionSpy );