Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #44 from ckeditor/t/ckeditor5/416d
Browse files Browse the repository at this point in the history
Feature: Enabled automatic items grouping in the main editor toolbar when there is not enough space to display them in a single row (see ckeditor/ckeditor5#416).
  • Loading branch information
jodator authored Oct 15, 2019
2 parents be7f15d + 8280e0e commit eb52505
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 32 deletions.
7 changes: 4 additions & 3 deletions src/decouplededitoruiview.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import EditorUIView from '@ckeditor/ckeditor5-ui/src/editorui/editoruiview';
import InlineEditableUIView from '@ckeditor/ckeditor5-ui/src/editableui/inline/inlineeditableuiview';
import ToolbarView from '@ckeditor/ckeditor5-ui/src/toolbar/toolbarview';
import Template from '@ckeditor/ckeditor5-ui/src/template';

/**
* The decoupled editor UI view. It is a virtual view providing an inline
Expand Down Expand Up @@ -41,7 +40,9 @@ export default class DecoupledEditorUIView extends EditorUIView {
* @readonly
* @member {module:ui/toolbar/toolbarview~ToolbarView}
*/
this.toolbar = new ToolbarView( locale );
this.toolbar = new ToolbarView( locale, {
shouldGroupWhenFull: true
} );

/**
* The editable of the decoupled editor UI.
Expand All @@ -55,7 +56,7 @@ export default class DecoupledEditorUIView extends EditorUIView {
// Because of the above, make sure the toolbar supports rounded corners.
// Also, make sure the toolbar has the proper dir attribute because its ancestor may not have one
// and some toolbar item styles depend on this attribute.
Template.extend( this.toolbar.template, {
this.toolbar.extendTemplate( {
attributes: {
class: [
'ck-reset_all',
Expand Down
60 changes: 31 additions & 29 deletions tests/decouplededitorui.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,38 +136,40 @@ describe( 'DecoupledEditorUI', () => {
} );
} );

describe( 'view.toolbar#items', () => {
it( 'are filled with the config.toolbar (specified as an Array)', () => {
return VirtualDecoupledTestEditor
.create( '', {
toolbar: [ 'foo', 'bar' ]
} )
.then( editor => {
const items = editor.ui.view.toolbar.items;

expect( items.get( 0 ).name ).to.equal( 'foo' );
expect( items.get( 1 ).name ).to.equal( 'bar' );

return editor.destroy();
} );
} );
describe( 'view.toolbar', () => {
describe( '#items', () => {
it( 'are filled with the config.toolbar (specified as an Array)', () => {
return VirtualDecoupledTestEditor
.create( '', {
toolbar: [ 'foo', 'bar' ]
} )
.then( editor => {
const items = editor.ui.view.toolbar.items;

expect( items.get( 0 ).name ).to.equal( 'foo' );
expect( items.get( 1 ).name ).to.equal( 'bar' );

return editor.destroy();
} );
} );

it( 'are filled with the config.toolbar (specified as an Object)', () => {
return VirtualDecoupledTestEditor
.create( '', {
toolbar: {
items: [ 'foo', 'bar' ],
viewportTopOffset: 100
}
} )
.then( editor => {
const items = editor.ui.view.toolbar.items;
it( 'are filled with the config.toolbar (specified as an Object)', () => {
return VirtualDecoupledTestEditor
.create( '', {
toolbar: {
items: [ 'foo', 'bar' ],
viewportTopOffset: 100
}
} )
.then( editor => {
const items = editor.ui.view.toolbar.items;

expect( items.get( 0 ).name ).to.equal( 'foo' );
expect( items.get( 1 ).name ).to.equal( 'bar' );
expect( items.get( 0 ).name ).to.equal( 'foo' );
expect( items.get( 1 ).name ).to.equal( 'bar' );

return editor.destroy();
} );
return editor.destroy();
} );
} );
} );
} );

Expand Down
4 changes: 4 additions & 0 deletions tests/decouplededitoruiview.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ describe( 'DecoupledEditorUIView', () => {
it( 'is not rendered', () => {
expect( view.toolbar.isRendered ).to.be.false;
} );

it( 'has automatic items grouping enabled', () => {
expect( view.toolbar.options.shouldGroupWhenFull ).to.be.true;
} );
} );

describe( '#editable', () => {
Expand Down

0 comments on commit eb52505

Please sign in to comment.