Browse Source

100% CC, minor improvements.

Kamil Piechaczek 5 years ago
parent
commit
f4a58c0472

+ 4 - 3
packages/ckeditor5-ui/src/bindings/clickoutsidehandler.js

@@ -30,9 +30,10 @@ export default function clickOutsideHandler( { emitter, activator, callback, con
 			return;
 		}
 
-		// Check if composedPath is undefined in case the browser does not support native shadow DOM
-		// Can be removed when all supported browsers support native shadow DOM
-		const path = domEvt.composedPath !== undefined ? domEvt.composedPath() : [];
+		// Check if `composedPath` is `undefined` in case the browser does not support native shadow DOM.
+		// Can be removed when all supported browsers support native shadow DOM.
+		const path = typeof domEvt.composedPath == 'function' ? domEvt.composedPath() : [];
+
 		for ( const contextElement of contextElements ) {
 			if ( contextElement.contains( domEvt.target ) || path.includes( contextElement ) ) {
 				return;

+ 22 - 0
packages/ckeditor5-ui/tests/bindings/clickoutsidehandler.js

@@ -55,6 +55,17 @@ describe( 'clickOutsideHandler', () => {
 		sinon.assert.calledOnce( actionSpy );
 	} );
 
+	it( 'should execute upon #mousedown outside of the contextElements (activator is active, unsupported shadow DOM)', () => {
+		activator.returns( true );
+
+		const event = new Event( 'mousedown', { bubbles: true } );
+		event.composedPath = undefined;
+
+		document.body.dispatchEvent( event );
+
+		sinon.assert.calledOnce( actionSpy );
+	} );
+
 	it( 'should execute upon #mousedown in the shadow root but outside the contextElements (activator is active)', () => {
 		activator.returns( true );
 
@@ -71,6 +82,17 @@ describe( 'clickOutsideHandler', () => {
 		sinon.assert.notCalled( actionSpy );
 	} );
 
+	it( 'should not execute upon #mousedown outside of the contextElements (activator is inactive, unsupported shadow DOM)', () => {
+		activator.returns( false );
+
+		const event = new Event( 'mousedown', { bubbles: true } );
+		event.composedPath = undefined;
+
+		document.body.dispatchEvent( event );
+
+		sinon.assert.notCalled( actionSpy );
+	} );
+
 	it( 'should not execute upon #mousedown in the shadow root but outside of the contextElements (activator is inactive)', () => {
 		activator.returns( false );