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

Commit

Permalink
Add toggleable config option.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Samsel committed Jul 16, 2019
1 parent 9ca56b7 commit a848522
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/button/buttonview.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,15 @@ import '../../theme/components/button/button.css';
*/
export default class ButtonView extends View {
/**
* @inheritDoc
* Creates an instance of the {@link module:ui/view~View} class.
*
* Also see {@link #render}.
*
* @param {module:utils/locale~Locale} [locale] The localization services instance.
* @param {Object} [config] additional configuration
* @param {Boolean} [config.toggleable=false] set button as toggleable
*/
constructor( locale ) {
constructor( locale, { toggleable = false } = {} ) {
super( locale );

const bind = this.bindTemplate;
Expand Down Expand Up @@ -131,8 +137,7 @@ export default class ButtonView extends View {
type: bind.to( 'type', value => value ? value : 'button' ),
tabindex: bind.to( 'tabindex' ),
'aria-labelledby': `ck-editor__aria-label_${ ariaLabelUid }`,
'aria-disabled': bind.if( 'isEnabled', true, value => !value ),
'aria-pressed': bind.to( 'isOn', value => value ? 'true' : 'false' )
'aria-disabled': bind.if( 'isEnabled', true, value => !value )
},

children: this.children,
Expand All @@ -155,6 +160,14 @@ export default class ButtonView extends View {
} )
}
} );

if ( toggleable ) {
this.extendTemplate( {
attributes: {
'aria-pressed': bind.to( 'isOn', value => value ? 'true' : 'false' )
}
} );
}
}

/**
Expand Down

0 comments on commit a848522

Please sign in to comment.