Browse Source

Fix: Refactor setting max-width for toolbar to handle tests scenarios

panr 5 years ago
parent
commit
89e6279159
1 changed files with 18 additions and 3 deletions
  1. 18 3
      packages/ckeditor5-editor-inline/src/inlineeditorui.js

+ 18 - 3
packages/ckeditor5-editor-inline/src/inlineeditorui.js

@@ -133,6 +133,10 @@ export default class InlineEditorUI extends EditorUI {
 
 		// https://github.com/ckeditor/ckeditor5-editor-inline/issues/4
 		view.listenTo( editor.ui, 'update', () => {
+			if ( !editableElement.ownerDocument.body.contains( editableElement ) ) {
+				return;
+			}
+
 			// Don't pin if the panel is not already visible. It prevents the panel
 			// showing up when there's no focus in the UI.
 			if ( view.panel.isVisible ) {
@@ -142,9 +146,8 @@ export default class InlineEditorUI extends EditorUI {
 				} );
 
 				// Set toolbar's max-width only once.
-				if ( !toolbar.element.style.maxWidth ) {
-					const editableRect = new Rect( editableElement );
-					toolbar.element.style.maxWidth = `${ editableRect.width }px`;
+				if ( toolbar.element.style.maxWidth === '' ) {
+					this._setToolbarMaxWidth( new Rect( editableElement ).width );
 				}
 			}
 		} );
@@ -182,4 +185,16 @@ export default class InlineEditorUI extends EditorUI {
 			} );
 		}
 	}
+
+	/**
+	 * Set max-width for toolbar.
+	 *
+	 * @private
+	 */
+	_setToolbarMaxWidth( width ) {
+		const view = this.view;
+		const toolbar = view.toolbar;
+
+		toolbar.element.style.maxWidth = `${ width }px`;
+	}
 }