Browse Source

Fix: ToolbarView should not be focusable.

Aleksander Nowodzinski 8 years ago
parent
commit
50d51ed8df

+ 7 - 1
packages/ckeditor5-ui/src/toolbar/toolbarview.js

@@ -13,6 +13,7 @@ import FocusTracker from '@ckeditor/ckeditor5-utils/src/focustracker';
 import FocusCycler from '../focuscycler';
 import KeystrokeHandler from '@ckeditor/ckeditor5-utils/src/keystrokehandler';
 import ToolbarSeparatorView from './toolbarseparatorview';
+import preventDefault from '../bindings/preventdefault.js';
 
 /**
  * The toolbar view class.
@@ -78,7 +79,12 @@ export default class ToolbarView extends View {
 				]
 			},
 
-			children: this.items
+			children: this.items,
+
+			on: {
+				// https://github.com/ckeditor/ckeditor5-ui/issues/206
+				mousedown: preventDefault( this )
+			}
 		} );
 
 		this.items.on( 'add', ( evt, item ) => {

+ 11 - 1
packages/ckeditor5-ui/tests/toolbar/toolbarview.js

@@ -3,7 +3,7 @@
  * For licensing, see LICENSE.md.
  */
 
-/* global document */
+/* global document, Event */
 
 import ToolbarView from '../../src/toolbar/toolbarview';
 import ToolbarSeparatorView from '../../src/toolbar/toolbarseparatorview';
@@ -64,6 +64,16 @@ describe( 'ToolbarView', () => {
 		it( 'should create element from template', () => {
 			expect( view.element.classList.contains( 'ck-toolbar' ) ).to.true;
 		} );
+
+		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( 'init()', () => {