8
0
Mateusz Samsel 6 лет назад
Родитель
Сommit
e2461bcabe
1 измененных файлов с 17 добавлено и 4 удалено
  1. 17 4
      packages/ckeditor5-ui/src/button/buttonview.js

+ 17 - 4
packages/ckeditor5-ui/src/button/buttonview.js

@@ -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.toggle=false] set button as a toggle
 	 */
-	constructor( locale ) {
+	constructor( locale, { toggle = false } = {} ) {
 		super( locale );
 
 		const bind = this.bindTemplate;
@@ -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,
@@ -155,6 +160,14 @@ export default class ButtonView extends View {
 				} )
 			}
 		} );
+
+		if ( toggle ) {
+			this.extendTemplate( {
+				attributes: {
+					'aria-pressed': bind.to( 'isOn', value => value ? 'true' : 'false' )
+				}
+			} );
+		}
 	}
 
 	/**