Skip to content

Commit

Permalink
100% CC, minor improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
pomek committed Aug 5, 2020
1 parent d30bcd7 commit f4a58c0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/ckeditor5-ui/src/bindings/clickoutsidehandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions packages/ckeditor5-ui/tests/bindings/clickoutsidehandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand All @@ -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 );

Expand Down

0 comments on commit f4a58c0

Please sign in to comment.