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

Commit

Permalink
Merge pull request #91 from ckeditor/t/ckeditor5/1404
Browse files Browse the repository at this point in the history
Other: The widget toolbar should have a proper `aria-label` attribute (see ckeditor/ckeditor5#1404).
  • Loading branch information
oleq authored Aug 13, 2019
2 parents 096d57a + 8b81bc6 commit aec5888
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
3 changes: 3 additions & 0 deletions lang/contexts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"Widget toolbar": "The label used by assistive technologies describing a toolbar attached to a widget."
}
8 changes: 6 additions & 2 deletions src/widgettoolbarrepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,17 @@ export default class WidgetToolbarRepository extends Plugin {
*
* @param {String} toolbarId An id for the toolbar. Used to
* @param {Object} options
* @param {String} [options.ariaLabel] Label used by assistive technologies to describe this toolbar element.
* @param {Array.<String>} options.items Array of toolbar items.
* @param {Function} options.getRelatedElement Callback which returns an element the toolbar should be attached to.
* @param {String} [options.balloonClassName='ck-toolbar-container'] CSS class for the widget balloon.
*/
register( toolbarId, { items, getRelatedElement, balloonClassName = 'ck-toolbar-container' } ) {
register( toolbarId, { ariaLabel, items, getRelatedElement, balloonClassName = 'ck-toolbar-container' } ) {
const editor = this.editor;
const toolbarView = new ToolbarView();
const t = editor.t;
const toolbarView = new ToolbarView( editor.locale );

toolbarView.ariaLabel = ariaLabel || t( 'Widget toolbar' );

if ( this._toolbarDefinitions.has( toolbarId ) ) {
/**
Expand Down
31 changes: 31 additions & 0 deletions tests/widgettoolbarrepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,37 @@ describe( 'WidgetToolbarRepository', () => {
} );
}, /^widget-toolbar-duplicated/, editor );
} );

it( 'should use a pre–defined aria-label for the toolbar', () => {
widgetToolbarRepository.register( 'fake', {
items: editor.config.get( 'fake.toolbar' ),
getRelatedElement: () => null
} );

const toolbarView = widgetToolbarRepository._toolbarDefinitions.get( 'fake' ).view;

toolbarView.render();

expect( toolbarView.element.getAttribute( 'aria-label' ) ).to.equal( 'Widget toolbar' );

toolbarView.destroy();
} );

it( 'should use a custom aria-label when provided', () => {
widgetToolbarRepository.register( 'fake', {
items: editor.config.get( 'fake.toolbar' ),
getRelatedElement: () => null,
ariaLabel: 'Custom label'
} );

const toolbarView = widgetToolbarRepository._toolbarDefinitions.get( 'fake' ).view;

toolbarView.render();

expect( toolbarView.element.getAttribute( 'aria-label' ) ).to.equal( 'Custom label' );

toolbarView.destroy();
} );
} );

describe( 'integration tests', () => {
Expand Down

0 comments on commit aec5888

Please sign in to comment.