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

Commit e58dadc

Browse files
authored
Merge pull request #64 from ckeditor/t/62
Fix: The default dropdown label shows 'Heading'. Closes #62.
2 parents 1115bc7 + 88f5d5d commit e58dadc

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

lang/contexts.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"Paragraph": "Drop-down option label for the paragraph format.",
3-
"Heading": "Tooltip for the heading drop-down.",
3+
"Heading": "Tooltip and default label for the heading drop-down.",
44
"Heading 1": "Drop-down option label for the heading level 1 format.",
55
"Heading 2": "Drop-down option label for the heading level 2 format.",
66
"Heading 3": "Drop-down option label for the heading level 3 format."

src/heading.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default class Heading extends Plugin {
3939
const options = this._getLocalizedOptions();
4040
const commands = [];
4141
const t = editor.t;
42-
let defaultOption;
42+
const defaultTitle = t( 'Heading' );
4343

4444
for ( let option of options ) {
4545
const command = editor.commands.get( option.modelElement );
@@ -55,17 +55,13 @@ export default class Heading extends Plugin {
5555
dropdownItems.add( itemModel );
5656

5757
commands.push( command );
58-
59-
if ( !defaultOption && option.modelElement == 'paragraph' ) {
60-
defaultOption = option;
61-
}
6258
}
6359

6460
// Create dropdown model.
6561
const dropdownModel = new Model( {
6662
withText: true,
6763
items: dropdownItems,
68-
tooltip: t( 'Heading' )
64+
tooltip: defaultTitle
6965
} );
7066

7167
dropdownModel.bind( 'isEnabled' ).to(
@@ -82,8 +78,8 @@ export default class Heading extends Plugin {
8278
( ...areActive ) => {
8379
const index = areActive.findIndex( value => value );
8480

85-
// If none of the commands is active, display the first one.
86-
return ( options[ index ] || defaultOption ).title;
81+
// If none of the commands is active, display default title.
82+
return options[ index ] ? options[ index ].title : defaultTitle;
8783
}
8884
);
8985

tests/heading.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
1414

1515
add( 'pl', {
1616
'Paragraph': 'Akapit',
17+
'Heading': 'Nagłówek',
1718
'Heading 1': 'Nagłówek 1',
1819
'Heading 2': 'Nagłówek 2',
1920
} );
@@ -56,7 +57,7 @@ describe( 'Heading', () => {
5657
expect( dropdown ).to.be.instanceOf( DropdownView );
5758
expect( dropdown.buttonView.isEnabled ).to.be.true;
5859
expect( dropdown.buttonView.isOn ).to.be.undefined;
59-
expect( dropdown.buttonView.label ).to.equal( 'Paragraph' );
60+
expect( dropdown.buttonView.label ).to.equal( 'Heading' );
6061
expect( dropdown.buttonView.tooltip ).to.equal( 'Heading' );
6162
} );
6263

@@ -108,7 +109,7 @@ describe( 'Heading', () => {
108109
commands[ name ].value = false;
109110
}
110111

111-
expect( dropdown.buttonView.label ).to.equal( 'Paragraph' );
112+
expect( dropdown.buttonView.label ).to.equal( 'Heading' );
112113

113114
commands.heading2.value = true;
114115
expect( dropdown.buttonView.label ).to.equal( 'Heading 2' );
@@ -137,7 +138,12 @@ describe( 'Heading', () => {
137138
it( 'works for the #buttonView', () => {
138139
const buttonView = dropdown.buttonView;
139140

141+
expect( buttonView.label ).to.equal( 'Nagłówek' );
142+
143+
commands.paragraph.value = true;
140144
expect( buttonView.label ).to.equal( 'Akapit' );
145+
146+
commands.paragraph.value = false;
141147
commands.heading1.value = true;
142148
expect( buttonView.label ).to.equal( 'Nagłówek 1' );
143149
} );

0 commit comments

Comments
 (0)