瀏覽代碼

Fix: BalloonPanelView should not be focusable.

Aleksander Nowodzinski 8 年之前
父節點
當前提交
4fa54729cc

+ 8 - 5
packages/ckeditor5-ui/src/panel/balloon/balloonpanelview.js

@@ -13,6 +13,7 @@ import { getOptimalPosition } from '@ckeditor/ckeditor5-utils/src/dom/position';
 import isRange from '@ckeditor/ckeditor5-utils/src/dom/isrange';
 import isElement from '@ckeditor/ckeditor5-utils/src/lib/lodash/isElement';
 import toUnit from '@ckeditor/ckeditor5-utils/src/dom/tounit';
+import preventDefault from '../../bindings/preventdefault.js';
 import global from '@ckeditor/ckeditor5-utils/src/dom/global';
 
 const toPx = toUnit( 'px' );
@@ -134,13 +135,15 @@ export default class BalloonPanelView extends View {
 					top: bind.to( 'top', toPx ),
 					left: bind.to( 'left', toPx ),
 					maxWidth: bind.to( 'maxWidth', toPx )
-				},
-
-				// Make this element `focusable` to be available for adding to FocusTracker.
-				tabindex: -1
+				}
 			},
 
-			children: this.content
+			children: this.content,
+
+			on: {
+				// https://github.com/ckeditor/ckeditor5-ui/issues/206
+				mousedown: preventDefault( this )
+			}
 		} );
 	}
 

+ 10 - 1
packages/ckeditor5-ui/tests/panel/balloon/balloonpanelview.js

@@ -35,7 +35,6 @@ describe( 'BalloonPanelView', () => {
 		it( 'should create element from template', () => {
 			expect( view.element.tagName ).to.equal( 'DIV' );
 			expect( view.element.classList.contains( 'ck-balloon-panel' ) ).to.true;
-			expect( view.element.getAttribute( 'tabindex' ) ).to.equal( '-1' );
 		} );
 
 		it( 'should set default values', () => {
@@ -129,6 +128,16 @@ describe( 'BalloonPanelView', () => {
 				} );
 			} );
 		} );
+
+		describe( 'event listeners', () => {
+			it( 'prevent default on #mousedown', () => {
+				const evt = new Event( 'mousedown', { bubbles: true } );
+				const spy = sinon.spy( evt, 'preventDefault' );
+
+				view.element.dispatchEvent( evt );
+				sinon.assert.calledOnce( spy );
+			} );
+		} );
 	} );
 
 	describe( 'show()', () => {