Skip to content

fix(2859) presentation role conflict - #2948

Merged
WilcoFiers merged 15 commits into
dequelabs:developfrom
clottman:2859-presentation-role-conflict
Jun 3, 2021
Merged

fix(2859) presentation role conflict#2948
WilcoFiers merged 15 commits into
dequelabs:developfrom
clottman:2859-presentation-role-conflict

Conversation

@clottman

Copy link
Copy Markdown
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
Comment thread lib/rules/presentation-role-conflict-matches.js Outdated
Comment thread lib/rules/presentation-role-conflict-matches.js Outdated
@clottman
clottman requested a review from WilcoFiers May 25, 2021 21:35
if (prohibited.length === 0) {
return false;
}

Copy link
Copy Markdown
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.

Comment thread lib/commons/aria/implicit-role.js Outdated
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
Copy Markdown
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
Copy Markdown
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 thread lib/commons/aria/implicit-role.js Outdated
Comment on lines +44 to +45
if (!role) {
if (chromiumRoles) {

Copy link
Copy Markdown
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
Copy Markdown
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;
}

Comment thread lib/commons/aria/implicit-role.js Outdated
Comment thread lib/rules/presentation-role-conflict-matches.js Outdated
Comment thread lib/rules/presentation-role-conflict.json Outdated
Comment thread lib/checks/aria/aria-prohibited-attr-evaluate.js Outdated
Comment thread lib/commons/aria/implicit-role.js Outdated
import { getNodeFromTree } from '../../core/utils';
import AbstractVirtuaNode from '../../core/base/virtual-node/abstract-virtual-node';

const implicitChromiumRoles = {

Copy link
Copy Markdown
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
Copy Markdown
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?

Comment thread lib/checks/aria/aria-prohibited-attr-evaluate.js Outdated
@clottman
clottman requested a review from WilcoFiers May 27, 2021 18:45
Comment thread lib/commons/aria/get-role.js Outdated
Comment thread lib/commons/aria/get-role.js Outdated
Comment thread lib/commons/aria/get-role.js Outdated
Comment thread lib/commons/aria/get-role.js Outdated
Comment thread lib/commons/aria/get-role.js Outdated
* @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
Copy Markdown
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.

contentTypes: ['phrasing', 'flow'],
allowedRoles: false
allowedRoles: false,
chromiumRole: 'progressbar'

Copy link
Copy Markdown
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
Copy Markdown
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)

},
allowedRoles: ['application']
allowedRoles: ['application'],
chromiumRole: 'video'

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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]>
WilcoFiers pushed a commit that referenced this pull request Aug 5, 2026
…low label and body from being named (#5259)

After looking over the HTML in ARIA spec, I realized that we could
better handle how we determine when an attribute is prohibited.
Basically if the element doesn't have an explicit role, then we use the
`htmlElm` spec to determine prohibited attrs and naming, otherwise we
use the `ariaRoles` spec to determine that. This should allow us to
eliminate the `elementsAllowedAriaLabel` option that was [introduced to
fix which elements allowed
naming](#2935) and then
modified when we [added Chromium
roles](#2948) to fix conflict
name resolution. However the option still has the `applet` element which
isn't in our html spec so I'm leaving it for now.

Elements which allow naming now include: `section`, `blockquote`,
`address`, `hgroup`, `ruby`.

This also adds enforcement for elements that are not allowed any aria-*
attribute (which has never been used in our code) by changing the
`noAriaAttrs` spec property to an empty `allowedAriaAttrs` so that they
now throw in the rule `aria-allowed-attr`.

Closes: #5185
Closes: #3410
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