Skip to content

Commit

Permalink
Add aria-checked attribute to align toolbars in table properties. (#…
Browse files Browse the repository at this point in the history
…17728)

Feature (table): Improve aria attributes in table and cell align toolbars. Closes #17722
  • Loading branch information
Mati365 authored Jan 10, 2025
1 parent 55ed74d commit 9333cc9
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ export default class TableCellPropertiesView extends View {

horizontalAlignmentToolbar.set( {
isCompact: true,
role: 'radiogroup',
ariaLabel: t( 'Horizontal text alignment toolbar' )
} );

Expand Down Expand Up @@ -745,6 +746,7 @@ export default class TableCellPropertiesView extends View {

verticalAlignmentToolbar.set( {
isCompact: true,
role: 'radiogroup',
ariaLabel: t( 'Vertical text alignment toolbar' )
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ export default class TablePropertiesView extends View {

const alignmentToolbar = new ToolbarView( locale! );
alignmentToolbar.set( {
role: 'radiogroup',
isCompact: true,
ariaLabel: t( 'Table alignment toolbar' )
} );
Expand Down
2 changes: 2 additions & 0 deletions packages/ckeditor5-table/src/utils/ui/table-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ export function fillToolbar<TView extends View, TPropertyName extends keyof TVie
const button = new ButtonView( view.locale );

button.set( {
role: 'radio',
isToggleable: true,
label: labels[ name ],
icon: icons[ name ],
tooltip: labels[ name ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,16 @@ describe( 'table cell properties', () => {
expect( toolbar.items.last.isOn ).to.be.false;
expect( toolbar.items.first.isOn ).to.be.true;
} );

it( 'should have proper ARIA properties', () => {
expect( toolbar.role ).to.equal( 'radiogroup' );
expect( toolbar.ariaLabel ).to.equal( 'Horizontal text alignment toolbar' );
} );

it( 'should have role=radio set on buttons', () => {
expect( [ ...toolbar.items ].some( ( { role, isToggleable } ) => role && isToggleable ) ).to.be.true;
expect( toolbar.items.length ).to.equal( 4 );
} );
} );

describe( 'vertical text alignment toolbar', () => {
Expand Down Expand Up @@ -599,6 +609,17 @@ describe( 'table cell properties', () => {
expect( toolbar.items.last.isOn ).to.be.false;
expect( toolbar.items.first.isOn ).to.be.true;
} );

it( 'should have proper ARIA properties', () => {
expect( toolbar.role ).to.equal( 'radiogroup' );
expect( toolbar.isCompact ).to.be.true;
expect( toolbar.ariaLabel ).to.equal( 'Vertical text alignment toolbar' );
} );

it( 'should have role=radio set on buttons', () => {
expect( [ ...toolbar.items ].some( ( { role, isToggleable } ) => role && isToggleable ) ).to.be.true;
expect( toolbar.items.length ).to.equal( 3 );
} );
} );
} );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,16 @@ describe( 'table properties', () => {
expect( toolbar.items.last.isOn ).to.be.false;
expect( toolbar.items.first.isOn ).to.be.true;
} );

it( 'should set proper ARIA properties', () => {
expect( toolbar.role ).to.equal( 'radiogroup' );
expect( toolbar.ariaLabel ).to.equal( 'Table alignment toolbar' );
} );

it( 'should have role=radio set on buttons', () => {
expect( [ ...toolbar.items ].some( ( { role, isToggleable } ) => role && isToggleable ) ).to.be.true;
expect( toolbar.items.length ).to.equal( 3 );
} );
} );
} );

Expand Down
11 changes: 10 additions & 1 deletion packages/ckeditor5-ui/src/toolbar/toolbarview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ export default class ToolbarView extends View implements DropdownPanelFocusable

declare public locale: Locale;

/**
* The property reflected by the `role` DOM attribute to be used by assistive technologies.
*
* @observable
* @default 'toolbar'
*/
declare public role: string | undefined;

/**
* Label used by assistive technologies to describe this toolbar element.
*
Expand Down Expand Up @@ -188,6 +196,7 @@ export default class ToolbarView extends View implements DropdownPanelFocusable

this.set( 'ariaLabel', t( 'Editor toolbar' ) );
this.set( 'maxWidth', 'auto' );
this.set( 'role', 'toolbar' );

this.items = this.createCollection();
this.focusTracker = new FocusTracker();
Expand Down Expand Up @@ -231,7 +240,7 @@ export default class ToolbarView extends View implements DropdownPanelFocusable
tag: 'div',
attributes: {
class: classes,
role: 'toolbar',
role: bind.to( 'role' ),
'aria-label': bind.to( 'ariaLabel' ),
style: {
maxWidth: bind.to( 'maxWidth' )
Expand Down
15 changes: 15 additions & 0 deletions packages/ckeditor5-ui/tests/toolbar/toolbarview.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,21 @@ describe( 'ToolbarView', () => {

view.destroy();
} );

it( 'should have proper ARIA properties', () => {
expect( view.element.getAttribute( 'role' ) ).to.equal( 'toolbar' );
} );

it( 'should allow customizing toolbar role', () => {
const view = new ToolbarView( locale );
view.role = 'radiogroup';

view.render();

expect( view.element.getAttribute( 'role' ) ).to.equal( 'radiogroup' );

view.destroy();
} );
} );

describe( 'event listeners', () => {
Expand Down

0 comments on commit 9333cc9

Please sign in to comment.