8
0
Pārlūkot izejas kodu

Add withArrow option to ContextualBalloon#add() method.

Maciej Gołaszewski 6 gadi atpakaļ
vecāks
revīzija
4764204f72

+ 4 - 1
packages/ckeditor5-ui/src/panel/balloon/contextualballoon.js

@@ -115,6 +115,7 @@ export default class ContextualBalloon extends Plugin {
 	 * @param {module:ui/view~View} [data.view] Content of the balloon.
 	 * @param {module:utils/dom/position~Options} [data.position] Positioning options.
 	 * @param {String} [data.balloonClassName] Additional css class for {@link #view} added when given view is visible.
+	 * @param {Boolean} [data.withArrow=true] Whether the {#_balloon} view should be rendered with arrow.
 	 */
 	add( data ) {
 		if ( this.hasView( data.view ) ) {
@@ -203,9 +204,11 @@ export default class ContextualBalloon extends Plugin {
 	 * @param {Object} data Configuration.
 	 * @param {module:ui/view~View} [data.view] View to show in the balloon.
 	 * @param {String} [data.balloonClassName=''] Additional class name which will added to the {#_balloon} view.
+	 * @param {Boolean} [data.withArrow=true] Whether the {#_balloon} view should be rendered with arrow.
 	 */
-	_show( { view, balloonClassName = '' } ) {
+	_show( { view, balloonClassName = '', withArrow = true } ) {
 		this.view.class = balloonClassName;
+		this.view.withArrow = withArrow;
 
 		this.view.content.add( view );
 		this.view.pin( this._getBalloonPosition() );

+ 41 - 0
packages/ckeditor5-ui/tests/panel/balloon/contextualballoon.js

@@ -299,6 +299,47 @@ describe( 'ContextualBalloon', () => {
 
 			expect( balloon.view.class ).to.equal( 'bar' );
 		} );
+
+		it( 'should hide arrow if `withArrow` option is set to false', () => {
+			balloon.remove( viewA );
+			balloon.view.pin.resetHistory();
+
+			balloon.add( {
+				view: viewB,
+				position: {
+					target: 'foo'
+				},
+				withArrow: false
+			} );
+
+			expect( balloon.view.withArrow ).to.be.false;
+		} );
+
+		it( 'should show arrow if `withArrow` option was not set and previously shown view had hidden arrow', () => {
+			balloon.remove( viewA );
+			balloon.view.pin.resetHistory();
+
+			balloon.add( {
+				view: viewB,
+				position: {
+					target: 'foo'
+				},
+				withArrow: false
+			} );
+
+			expect( balloon.view.withArrow ).to.be.false;
+
+			balloon.remove( viewB );
+
+			balloon.add( {
+				view: viewB,
+				position: {
+					target: 'foo'
+				}
+			} );
+
+			expect( balloon.view.withArrow ).to.be.true;
+		} );
 	} );
 
 	describe( 'visibleView', () => {