浏览代码

Fix: StickyToolbarView does not become sticky on #init if the conditions are met.

Aleksander Nowodzinski 8 年之前
父节点
当前提交
083f444ca4

+ 3 - 0
packages/ckeditor5-ui/src/toolbar/sticky/stickytoolbarview.js

@@ -192,6 +192,9 @@ export default class StickyToolbarView extends ToolbarView {
 
 		this.element.parentNode.insertBefore( this._elementPlaceholder, this.element );
 
+		// Check if the toolbar should go into the sticky state immediately.
+		this._checkIfShouldBeSticky();
+
 		// Update sticky state of the toolbar as the window is being scrolled.
 		this.listenTo( global.window, 'scroll', () => {
 			this._checkIfShouldBeSticky();

+ 12 - 4
packages/ckeditor5-ui/tests/toolbar/sticky/stickytoolbarview.js

@@ -163,13 +163,21 @@ describe( 'StickyToolbarView', () => {
 			expect( element.previousSibling ).to.equal( view._elementPlaceholder );
 		} );
 
+		it( 'checks if the toolbar should be sticky', () => {
+			const spy = testUtils.sinon.spy( view, '_checkIfShouldBeSticky' );
+			expect( spy.notCalled ).to.be.true;
+
+			view.init();
+			expect( spy.calledOnce ).to.be.true;
+		} );
+
 		it( 'listens to window#scroll event and calls view._checkIfShouldBeSticky', () => {
 			const spy = testUtils.sinon.spy( view, '_checkIfShouldBeSticky' );
+			expect( spy.notCalled ).to.be.true;
 
 			view.init();
 			global.window.fire( 'scroll' );
-
-			expect( spy.calledOnce ).to.be.true;
+			expect( spy.calledTwice ).to.be.true;
 		} );
 
 		it( 'listens to view.isActive and calls view._checkIfShouldBeSticky', () => {
@@ -178,10 +186,10 @@ describe( 'StickyToolbarView', () => {
 
 			view.init();
 			view.isActive = true;
-			expect( spy.calledOnce ).to.be.true;
+			expect( spy.calledTwice ).to.be.true;
 
 			view.isActive = false;
-			expect( spy.calledTwice ).to.be.true;
+			expect( spy.calledThrice ).to.be.true;
 		} );
 	} );