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

Prevented ContextualToolbar from being showed when all comonents inside are disabled.

Oskar Wróbel 8 лет назад
Родитель
Сommit
ffe0302502

+ 6 - 0
packages/ckeditor5-ui/src/toolbar/contextual/contextualtoolbar.js

@@ -177,6 +177,12 @@ export default class ContextualToolbar extends Plugin {
 	 * @private
 	 */
 	_show() {
+		// Don not show ContextualToolbar when all components inside are disabled
+		// see https://github.com/ckeditor/ckeditor5-ui/issues/269.
+		if ( Array.from( this.toolbarView.items ).every( item => !item.isEnabled ) ) {
+			return;
+		}
+
 		// Update panel position when selection changes (by external document changes) while balloon is opened.
 		this.listenTo( this.editor.editing.view, 'render', () => {
 			this._balloon.updatePosition( this._getBalloonPositionData() );

+ 10 - 0
packages/ckeditor5-ui/tests/toolbar/contextual/contextualtoolbar.js

@@ -217,6 +217,16 @@ describe( 'ContextualToolbar', () => {
 			sinon.assert.calledOnce( balloonAddSpy );
 		} );
 
+		it( 'should not add #toolbarView to the #_balloon when all components inside #toolbarView are disabled', () => {
+			Array.from( contextualToolbar.toolbarView.items ).forEach( item => {
+				item.isEnabled = false;
+			} );
+			setData( editor.document, '<paragraph>b[a]r</paragraph>' );
+
+			contextualToolbar.show();
+			sinon.assert.notCalled( balloonAddSpy );
+		} );
+
 		describe( 'on #_selectionChangeDebounced event', () => {
 			let showSpy;