Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose toggle buttons in accessibility tree #5123

Merged
merged 26 commits into from
Apr 9, 2022
Merged

Expose toggle buttons in accessibility tree #5123

merged 26 commits into from
Apr 9, 2022

Conversation

Comandeer
Copy link
Member

@Comandeer Comandeer commented Mar 12, 2022

What is the purpose of this pull request?

New feature

Does your PR contain necessary tests?

All patches that change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.

This PR contains

  • Unit tests
  • Manual tests

Did you follow the CKEditor 4 code style guide?

Your code should follow the guidelines from the CKEditor 4 code style guide which helps keep the entire codebase consistent.

  • PR is consistent with the code style guide

What is the proposed changelog entry for this pull request?

New features:

* [#2444](https://github.com/ckeditor/ckeditor4/issues/2444): Togglable toolbar buttons are now exposed as toggle buttons in the browser's accessibility tree.

Fixed Issues:

* [#4543](https://github.com/ckeditor/ckeditor4/issues/4543): The selected states of toolbar buttons are not announced by screen readers.

What changes did you make?

I've changed the way of handling the [aria-pressed] attribute in the button plugin. After the changes, the attribute is always present on the button and only its value is changed (previously the attribute was removed when the button was not pressed). Additionally, I've added the isToggle option to the button's definition which indicates that the button is togglable (this option is needed to handle the initial state of the toggle buttons).

I've then added isToogle option to plugins using toggle buttons:

  • basicstyles,
  • bidi,
  • blockquote,
  • copyformatting,
  • justify,
  • list,
  • sourcearea.

However, there are still some plugins that require additional attention:

  • language and colorbutton – these plugins use menu buttons that are also togglable, however, screen readers do not support such combination, so the information about the state of the toggle button is lost,
  • maximize – this plugin uses the toggle button but instead of conveying the state using the [aria-pressed] attribute, it changes the label of the button (from "Maximize" to "Minimize"; I'd suggest replacing the current method with the [aria-pressed] one, used in other plugins.

Which issues does your PR resolve?

Closes #2444.
Closes #4543.

@Comandeer Comandeer self-assigned this Mar 15, 2022
@Comandeer
Copy link
Member Author

I've updated the maximize plugin to also use [aria-pressed] attribute instead of a dynamic label.

@Comandeer Comandeer removed their assignment Mar 15, 2022
@jacekbogdanski jacekbogdanski self-assigned this Mar 22, 2022
@jacekbogdanski jacekbogdanski self-requested a review March 22, 2022 11:03
Copy link
Member

@jacekbogdanski jacekbogdanski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBC

plugins/button/plugin.js Outdated Show resolved Hide resolved
if ( this.isToggle && !this.hasArrow ) {
// Note: aria-pressed attribute should not be added to menuButton instances. (https://dev.ckeditor.com/ticket/11331).
// Do not remove the attribute, set its value (#2444).
element.setAttribute( 'aria-pressed', state === CKEDITOR.TRISTATE_ON );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it's not introducing a breaking change. If someone is already using a button (3rd party plugin) without an arrow, it supports the aria-pressed feature. Maybe we should instead keep the previous logic for the non-defined isToggle value?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we have never supported [aria-pressed] on menubuttons – the only change I've introduced here is the explicit check if the button is a toggle one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it was setting aria-pressed for !this.hasArrow check? Although I don't see it to be working correctly before your changes on VoiceOver despite having aria-pressed="true" for toggled button - not sure why.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because toggle buttons are identified by the presence of the [aria-pressed] attribute. If the attribute is not present, it's considered a normal button. So adding that attribute only for the true value causes that the button is a toggle one only when it's pressed (in Chrome it isn't at all).

Comment on lines -251 to -260
// Toggle button label.
var button = this.uiItems[ 0 ];
// Only try to change the button if it exists (https://dev.ckeditor.com/ticket/6166)
if ( button ) {
var label = ( this.state == CKEDITOR.TRISTATE_OFF ) ? lang.maximize.maximize : lang.maximize.minimize;
var buttonNode = CKEDITOR.document.getById( button._.id );
buttonNode.getChild( 1 ).setHtml( label );
buttonNode.setAttribute( 'title', label );
buttonNode.setAttribute( 'href', 'javascript:void("' + label + '");' ); // jshint ignore:line
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't we losing some information about the second behavior of the button with that change? Previously, this button was nicely labeled with minimize once maximized. Now, it looks like this change favors screen readers only. Is it possible to keep both an aria-pressed attribute and a label (in the context of accessibility)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, "Maximize" is the only button that works this way. Every other one does not toggle its label, instead, they apply the correct value of the [aria-pressed] attribute.

Additionally, I do not think that the information is lost. The fact that the editor is maximized is communicated via two things: maximized editor (obviously) and the styling of the pressed button. It's analogous to other toggle buttons, e.g. "Bold" – we have a pressed "Bold" button, not a pressed "Unbold" button.

And a small nitpick – I really think that "MInimize" means something slightly different than restoring the maximized window to its original size 😛

Copy link
Member

@jacekbogdanski jacekbogdanski Mar 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that makes sense, thanks for the explanation 👍🏻

@Comandeer
Copy link
Member Author

I've removed the unnecessary template for the [aria-pressed] attribute.

@Comandeer Comandeer removed their assignment Mar 23, 2022
@jacekbogdanski jacekbogdanski self-assigned this Mar 25, 2022
Copy link
Member

@jacekbogdanski jacekbogdanski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes look good but I was only able to do manual tests using VoiceOver as my VM machines decided to not support OS sounds. @sculpt0r could you give it a try and confirm that manual test for screen readers works correctly on JAWS + Firefox and NVDA?

There is one issue but I'm not sure if it's related to your changes. Toggling source area forces the screen reader (VoiceOver) to read some garbage about being inside a table (for manual test with a table) or inside a list (for nightly sample). I'm not sure, but it looks like screen reader focus goes somewhere else after toggling a button?

tests/plugins/button/manual/togglebutton.md Outdated Show resolved Hide resolved
tests/plugins/button/manual/togglebuttonscreenreader.md Outdated Show resolved Hide resolved
if ( this.isToggle && !this.hasArrow ) {
// Note: aria-pressed attribute should not be added to menuButton instances. (https://dev.ckeditor.com/ticket/11331).
// Do not remove the attribute, set its value (#2444).
element.setAttribute( 'aria-pressed', state === CKEDITOR.TRISTATE_ON );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it was setting aria-pressed for !this.hasArrow check? Although I don't see it to be working correctly before your changes on VoiceOver despite having aria-pressed="true" for toggled button - not sure why.

tests/plugins/button/_helpers/buttontools.js Outdated Show resolved Hide resolved
@Comandeer
Copy link
Member Author

There is one issue but I'm not sure if it's related to your changes. Toggling source area forces the screen reader (VoiceOver) to read some garbage about being inside a table (for manual test with a table) or inside a list (for nightly sample). I'm not sure, but it looks like screen reader focus goes somewhere else after toggling a button?

That's weird 🤔 The focus does not go anywhere, it stays on the button. The issue you describe appears only in Chrome, I can't reproduce it in Firefox or Safari. It looks like a browser bug.

@Comandeer
Copy link
Member Author

I've fixed the reported codestyle issues.

@sculpt0r sculpt0r self-assigned this Mar 28, 2022
@sculpt0r sculpt0r self-requested a review March 28, 2022 08:54
Comandeer and others added 2 commits March 28, 2022 12:16
Co-authored-by: Jacek Bogdański <jacekbogd@gmail.com>
@sculpt0r
Copy link
Contributor

Rebased onto the newest master

Copy link
Contributor

@sculpt0r sculpt0r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Comandeer nice work with the test tooling 👍

JAWS & NVDA works fine 🎉 I have only doubts about naming and other small stuff in a few places - please take a look at the inline comments.

Additionally - I think we should add a test with the language button in the toolbar. It is not the plain toggle button, but the code around hasArrow was changed and it will be good to verify whenever this button still works as we expected - also with screen readers.

plugins/button/plugin.js Show resolved Hide resolved
plugins/button/plugin.js Show resolved Hide resolved
tests/plugins/maximize/manual/togglebutton.md Outdated Show resolved Hide resolved
tests/plugins/button/_helpers/buttontools.js Outdated Show resolved Hide resolved
plugins/button/plugin.js Outdated Show resolved Hide resolved
@Comandeer Comandeer self-assigned this Mar 30, 2022
Comandeer and others added 4 commits March 30, 2022 10:32
Co-authored-by: Bartłomiej Kalemba <b.kalemba@cksource.com>
Co-authored-by: Bartłomiej Kalemba <b.kalemba@cksource.com>
@Comandeer
Copy link
Member Author

Ok, I've refactored names a bit and added a manual test for screen readers and menu button.

@Comandeer Comandeer requested a review from sculpt0r March 30, 2022 10:14
@sculpt0r sculpt0r self-assigned this Mar 31, 2022
Copy link
Contributor

@sculpt0r sculpt0r left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

Thank you for the separated test for the menu button. Thanks to that, I found and extracted an issue with aria-expanded: #5144

Added a changelog.

@sculpt0r
Copy link
Contributor

@Comandeer - we have to wait for @jacekbogdanski approval - since he also reviewed this PR. Without it, GH is blocking me with the merge.

@github-actions
Copy link

github-actions bot commented Apr 8, 2022

It's been a while since we last heard from you. We are marking this pull request as stale due to inactivity. Please provide the requested feedback or the pull request will be closed after next 7 days.

@github-actions github-actions bot added the stale The issue / PR will be closed within the next 7 days of inactivity. label Apr 8, 2022
@Comandeer Comandeer removed the stale The issue / PR will be closed within the next 7 days of inactivity. label Apr 8, 2022
Comment on lines +8 to +10
New features:

* [#2444](https://github.com/ckeditor/ckeditor4/issues/2444): Togglable toolbar buttons are now exposed as toggle buttons in the browser's accessibility tree.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A feature changelog entry should go to a major release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants