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

Set UI buttons as toggleable #246

Merged
merged 3 commits into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/linkui.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,11 @@ export default class LinkUI extends Plugin {
button.icon = linkIcon;
button.keystroke = linkKeystroke;
button.tooltip = true;
button.isToggleable = true;

// Bind button to the command.
button.bind( 'isOn', 'isEnabled' ).to( linkCommand, 'value', 'isEnabled' );
button.bind( 'isEnabled' ).to( linkCommand, 'isEnabled' );
button.bind( 'isOn' ).to( linkCommand, 'value', value => !!value );

// Show the panel on button click.
this.listenTo( button, 'execute', () => this._showUI( true ) );
Expand Down
8 changes: 6 additions & 2 deletions tests/linkui.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,21 @@ describe( 'LinkUI', () => {
expect( linkButton ).to.be.instanceOf( ButtonView );
} );

it( 'should be toggleable button', () => {
expect( linkButton.isToggleable ).to.be.true;
} );

it( 'should be bound to the link command', () => {
const command = editor.commands.get( 'link' );

command.isEnabled = true;
command.value = true;
command.value = 'http://ckeditor.com';

expect( linkButton.isOn ).to.be.true;
expect( linkButton.isEnabled ).to.be.true;

command.isEnabled = false;
command.value = false;
command.value = undefined;

expect( linkButton.isOn ).to.be.false;
expect( linkButton.isEnabled ).to.be.false;
Expand Down