Bladeren bron

Hide the panel of the BlockToolbar on toolbar blur.

Oskar Wróbel 7 jaren geleden
bovenliggende
commit
7b76823e64

+ 9 - 4
packages/ckeditor5-ui/src/toolbar/block/blocktoolbar.js

@@ -162,10 +162,15 @@ export default class BlockToolbar extends Plugin {
 
 		toolbarView.extendTemplate( {
 			attributes: {
-				class: [
-					// https://github.com/ckeditor/ckeditor5-editor-inline/issues/11
-					'ck-toolbar_floating'
-				]
+				// https://github.com/ckeditor/ckeditor5-editor-inline/issues/11
+				class: [ 'ck-toolbar_floating' ]
+			}
+		} );
+
+		// When toolbar lost focus then panel should hide.
+		toolbarView.focusTracker.on( 'change:isFocused', ( evt, name, is ) => {
+			if ( !is ) {
+				this._hidePanel();
 			}
 		} );
 

+ 10 - 0
packages/ckeditor5-ui/tests/toolbar/block/blocktoolbar.js

@@ -133,6 +133,16 @@ describe( 'BlockToolbar', () => {
 
 				expect( blockToolbar.panelView.isVisible ).to.be.false;
 			} );
+
+			it( 'should hide the panel on toolbar blur', () => {
+				blockToolbar.buttonView.fire( 'execute' );
+
+				expect( blockToolbar.panelView.isVisible ).to.be.true;
+
+				blockToolbar.toolbarView.focusTracker.isFocused = false;
+
+				expect( blockToolbar.panelView.isVisible ).to.be.false;
+			} );
 		} );
 
 		describe( 'buttonView', () => {