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

fix(2859) presentation role conflict #2948

Merged

Conversation

clottman
Copy link
Contributor

Adds a matcher to the presentation-role-conflict rule so that only elements that have an implicit role that could potentially conflict with an explicit role should be tested against the rule.

Since divs don't have an implicit role and thus should not be matched by the rule, two of the passing tests had to be removed.

Closes issue: #2859

@clottman clottman requested a review from a team as a code owner May 19, 2021 21:04
@WilcoFiers WilcoFiers self-assigned this May 21, 2021
@clottman clottman requested a review from WilcoFiers May 25, 2021 21:35
});

if (prohibited.length === 0) {
return false;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Odd, looks like prettier isn't running on my machine :/. I'll have to look at that.

lib/commons/aria/implicit-role.js Outdated Show resolved Hide resolved
Comment on lines -28 to -32
// until we have proper implicit role lookups for svgs we will
// avoid giving them one
if (node && node.namespaceURI === 'http://www.w3.org/2000/svg') {
return null;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looked like an unnecessary check - we don't have implicit role lookups for svg, so it will return null without this check based on the lines that follow.

If we left it in, we'd have to add another check here for whether to use the chromium roles, and return the svg's implicit chromium role or else null. That's the same logic as is below.

Comment on lines 44 to 45
if (!role) {
if (chromiumRoles) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a fan of these double if's. Can you refactor so this function flattens out? Could probably just do a return role || null at the end of the function, instead of returning null in a separate if.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Were you thinking something like this?

  if (!role && chromiumRoles) {
    const chromiumRole = implicitChromiumRoles[nodeName];
    return chromiumRole || null;
  }

  if (typeof role === 'function') {
    return role(vNode);
  }

  return role || null;
}

lib/commons/aria/implicit-role.js Outdated Show resolved Hide resolved
lib/rules/presentation-role-conflict-matches.js Outdated Show resolved Hide resolved
lib/rules/presentation-role-conflict.json Outdated Show resolved Hide resolved
lib/checks/aria/aria-prohibited-attr-evaluate.js Outdated Show resolved Hide resolved
@@ -2,6 +2,19 @@ import implicitHtmlRoles from '../standards/implicit-html-roles';
import { getNodeFromTree } from '../../core/utils';
import AbstractVirtuaNode from '../../core/base/virtual-node/abstract-virtual-node';

const implicitChromiumRoles = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at this list now... this could probably just be a property on standards/html-elms.js. That's probably better, that would make it configurable. So maybe something like:

const htmlElms = {
  audio: {
    ...otherProps,
    chromiumRole: 'Audio'
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would that be preferable to including it on standards/implicit-html-roles, which is currently what getImplicitRole uses?

lib/checks/aria/aria-prohibited-attr-evaluate.js Outdated Show resolved Hide resolved
@clottman clottman requested a review from WilcoFiers May 27, 2021 18:45
lib/commons/aria/get-role.js Outdated Show resolved Hide resolved
lib/commons/aria/get-role.js Outdated Show resolved Hide resolved
lib/commons/aria/get-role.js Outdated Show resolved Hide resolved
lib/commons/aria/get-role.js Outdated Show resolved Hide resolved
@@ -158,6 +165,7 @@ function resolveRole(node, { noImplicit, ...explicitRoleOptions } = {}) {
* @param {boolean} options.abstracts Allow role to be abstract
* @param {boolean} options.dpub Allow role to be any (valid) doc-* roles
* @param {boolean} options.noPresentational return null if role is presentation or none
* @param {boolean} options.includeChromiumRoles Include implicit roles from chromium-based browsers in role result
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks a little out of place with the rest. Just calling it .options.chormium seems like it would be more consistent with the other options here.

@@ -601,7 +607,8 @@ const htmlElms = {
},
meter: {
contentTypes: ['phrasing', 'flow'],
allowedRoles: false
allowedRoles: false,
chromiumRole: 'progressbar'
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be capitalised? If it isn't in Chromium then not, but it seems inconsistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, they are all inconsistent in Chrome(ium)

@@ -914,7 +923,8 @@ const htmlElms = {
contentTypes: ['embedded', 'phrasing', 'flow']
}
},
allowedRoles: ['application']
allowedRoles: ['application'],
chromiumRole: 'video'
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here. Why is it Audio but not Video?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same answer - it's inconsistently reported in the browser.

import { getImplicitRole } from '../commons/aria';

function hasImplicitChromiumRoleMatches(node, virtualNode) {
return getImplicitRole(virtualNode) !== null;
Copy link
Contributor

Choose a reason for hiding this comment

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

This still needs to use the new option. We'll need tests for it too.

@clottman clottman requested a review from WilcoFiers June 1, 2021 19:28
@WilcoFiers
Copy link
Contributor

Reviewed for security.

@WilcoFiers WilcoFiers merged commit 5ccc797 into dequelabs:develop Jun 3, 2021
straker pushed a commit that referenced this pull request Jun 3, 2021
* fix typo

* add matcher so rule only applies when element has an implicit role that could conflict

* add matcher so rule only applies when element has an implicit role that could conflict

* use virtual node

* add chromium implicit roles to lookup

* remove temp variable

Co-authored-by: Wilco Fiers <[email protected]>

* use chromiumroles for getimplicitrole in this matcher

Co-authored-by: Wilco Fiers <[email protected]>

* rename chromiumRoles to includeChromiumRoles to add clarity and add it to getRole

* refactor aria-prohibited-attr and add test

* rename to has-implicit-chromium-role-matches

* put chromium role on standards/html-elm and use it to get the implicit chromium role

* consolidate function parameters

Co-authored-by: Wilco Fiers <[email protected]>

* rename option to just chromium

Co-authored-by: Wilco Fiers <[email protected]>
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.

2 participants