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

feat(new-rule): aria-braille-equivalent finds incorrect uses of aria-braille attributes #4107

Merged
merged 5 commits into from
Jul 31, 2023

Conversation

WilcoFiers
Copy link
Contributor

This rule effectively checks two things:

  1. aria-braillelabel is only ever used on elements with an accessible name
  2. aria-brailleroledescription is only ever used on elements with aria-roledescription

Closes: #3955

@WilcoFiers WilcoFiers requested a review from a team as a code owner July 28, 2023 12:29
virtualNode
) {
const brailleLabel = virtualNode.attr('aria-braillelabel') ?? '';
if (!brailleLabel.trim()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use sanitize from our text functions here instead (similar to aria-label and aria-labelledby checks)?

Copy link
Contributor Author

@WilcoFiers WilcoFiers Jul 31, 2023

Choose a reason for hiding this comment

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

We probably shouldn't use it for aria-labelledby either. What sanitize does that trim doesn't do is replace duplicate whitespace characters in between words with single space characters. We don't need that here.

Suppose it doesn't matter much though. And if we do ever need to do this in a way that's different from trim it helps to have them in place.

"metadata": {
"impact": "serious",
"messages": {
"pass": "aria-braillelabel is not used on an element with no accessible text",
Copy link
Contributor

Choose a reason for hiding this comment

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

Just simplifying the double negative.

Suggested change
"pass": "aria-braillelabel is not used on an element with no accessible text",
"pass": "aria-braillelabel is used on an element with accessible text",

virtualNode
) {
const brailleRoleDesc = virtualNode.attr('aria-brailleroledescription') ?? '';
if (!brailleRoleDesc.trim()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto for sanitize

return false;
}

if (roleDesc.trim() === '') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should keep consistent use of if you're using !brailleRoleDesc.trim() or brailleRoleDesc.trim() === '')

"metadata": {
"impact": "serious",
"messages": {
"pass": "aria-brailleroledescription is not used on an element with no accessible text",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"pass": "aria-brailleroledescription is not used on an element with no accessible text",
"pass": "aria-brailleroledescription is used on an element with aria-roledescription",

describe('when aria-braillelabel has text', () => {
it('returns false when the accessible name is empty', () => {
const params = checkSetup(`
<img id="target" alt="" aria-braillelabel="foo" />
Copy link
Contributor

Choose a reason for hiding this comment

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

This brings up an interesting question. This element is essentially role=presentation and thus won't be seen by the accessibility tree and thus I assume braille machines. Do we want to fail for these cases or do something similar to button-name rule and add the presentational-role check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this should fail. There's no reason someone would put aria-braillelabel on an element like this. We might change how that works if this attribute ever goes on the prohibited attrs list, which is what I asked the ARIA WG about. I think that would be more appropriate. Until then I think this is reasonable.

Comment on lines +2 to +4
afterEach(() => {
axe.reset();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe this isn't necessary

Suggested change
afterEach(() => {
axe.reset();
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Configuration isn't reverted until axe.reset() is called. It's not in testutils. Where would you think this might happen?

Copy link
Contributor

@straker straker Jul 31, 2023

Choose a reason for hiding this comment

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

The audit is reverted back to the original one in the beforeEach. Don't remember why we didn't use axe.reset there, maybe we should (in a different pr)? Either way, it's not strictly something that needs to hold up this pr.

assert.lengthOf(results.incomplete, 0);
});

it('fails when roledescription is empty but brailleroledescription is not', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe accessibleTextVirtual can throw in subtree text if the element doesn't have a child (See https://github.com/dequelabs/axe-core/blob/develop/test/integration/virtual-rules/button-name.js#L116-L125). If that's the case, we should add a test for incomplete.

straker
straker previously approved these changes Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New rule: restrict use of aria-description and aria-braille*
2 participants