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

Commit

Permalink
Feature: The main editor toolbar should respect the config.toolbar.sh…
Browse files Browse the repository at this point in the history
…ouldGroupWhenFull configuration.
  • Loading branch information
oleq committed Nov 18, 2019
1 parent b5e4793 commit 932e90d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/classiceditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ export default class ClassicEditor extends Editor {

this.model.document.createRoot();

this.ui = new ClassicEditorUI( this, new ClassicEditorUIView( this.locale, this.editing.view ) );
const shouldGroupWhenFull = this.config.get( 'toolbar.shouldGroupWhenFull' );
const view = new ClassicEditorUIView( this.locale, this.editing.view, {
shouldToolbarGroupWhenFull: shouldGroupWhenFull === undefined ? true : shouldGroupWhenFull
} );

this.ui = new ClassicEditorUI( this, view );

attachToForm( this );
}
Expand Down
8 changes: 6 additions & 2 deletions src/classiceditoruiview.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ export default class ClassicEditorUIView extends BoxedEditorUIView {
*
* @param {module:utils/locale~Locale} locale The {@link module:core/editor/editor~Editor#locale} instance.
* @param {module:engine/view/view~View} editingView The editing view instance this view is related to.
* @param {Object} [options={}] Configuration options fo the view instance.
* @param {Boolean} [options.shouldToolbarGroupWhenFull] When set `true` enables automatic items grouping
* in the main {@link module:editor-classic/classiceditoruiview~ClassicEditorUIView#toolbar toolbar}.
* See {@link module:ui/toolbar/toolbarview~ToolbarOptions#shouldGroupWhenFull} to learn more.
*/
constructor( locale, editingView ) {
constructor( locale, editingView, options = {} ) {
super( locale );

/**
Expand All @@ -46,7 +50,7 @@ export default class ClassicEditorUIView extends BoxedEditorUIView {
* @member {module:ui/toolbar/toolbarview~ToolbarView}
*/
this.toolbar = new ToolbarView( locale, {
shouldGroupWhenFull: true
shouldGroupWhenFull: options.shouldToolbarGroupWhenFull
} );

/**
Expand Down
24 changes: 24 additions & 0 deletions tests/classiceditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,30 @@ describe( 'ClassicEditor', () => {
expect( editor.ui ).to.be.instanceof( ClassicEditorUI );
expect( editor.ui.view ).to.be.instanceof( ClassicEditorUIView );
} );

describe( 'automatic toolbar items groupping', () => {
it( 'should be on by default', () => {
const editorElement = document.createElement( 'div' );
const editor = new ClassicEditor( editorElement );

expect( editor.ui.view.toolbar.options.shouldGroupWhenFull ).to.be.true;

editorElement.remove();
} );

it( 'can be disabled using config.toolbar.shouldGroupWhenFull', () => {
const editorElement = document.createElement( 'div' );
const editor = new ClassicEditor( editorElement, {
toolbar: {
shouldGroupWhenFull: false
}
} );

expect( editor.ui.view.toolbar.options.shouldGroupWhenFull ).to.be.false;

editorElement.remove();
} );
} );
} );
} );

Expand Down
22 changes: 20 additions & 2 deletions tests/classiceditoruiview.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,26 @@ describe( 'ClassicEditorUIView', () => {
expect( view.stickyPanel.content.get( 0 ) ).to.equal( view.toolbar );
} );

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

it( 'should be controlled via options.shouldToolbarGroupWhenFull', () => {
const locale = new Locale();
const editingView = new EditingView();
const editingViewRoot = createRoot( editingView.document );
const view = new ClassicEditorUIView( locale, editingView, {
shouldToolbarGroupWhenFull: true
} );

view.editable.name = editingViewRoot.rootName;
view.render();

expect( view.toolbar.options.shouldGroupWhenFull ).to.be.true;

return view.destroy();
} );
} );
} );

Expand Down

0 comments on commit 932e90d

Please sign in to comment.