Ver Fonte

Fix: Refactor setting max-width for toolbar as a private method for testing purposes

panr há 6 anos atrás
pai
commit
88a634d6e2

+ 11 - 3
packages/ckeditor5-ui/src/toolbar/balloon/balloontoolbar.js

@@ -190,10 +190,9 @@ export default class BalloonToolbar extends Plugin {
 		} );
 
 		// Set toolbar's max-width to be half of the editable's width.
-		const editableRect = new Rect( this.editor.editing.view.getDomRoot() );
-		const maxToolbarWidth = editableRect.width / 2;
+		const maxToolbarWidth = new Rect( this.editor.editing.view.getDomRoot() ).width;
 
-		this.toolbarView.element.style.maxWidth = `${ maxToolbarWidth }px`;
+		this._setToolbarMaxWidth( maxToolbarWidth / 2 );
 
 		// Add the toolbar to the common editor contextual balloon.
 		this._balloon.add( {
@@ -268,6 +267,15 @@ export default class BalloonToolbar extends Plugin {
 		this.focusTracker.destroy();
 	}
 
+	/**
+	 * Set max-width for toolbar.
+	 *
+	 * @private
+	 */
+	_setToolbarMaxWidth( width ) {
+		this.toolbarView.element.style.maxWidth = `${ width }px`;
+	}
+
 	/**
 	 * This event is fired just before the toolbar shows up. Stopping this event will prevent this.
 	 *