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

[WIP] feat(rule): label content name mismatch #1159

Closed
wants to merge 2 commits into from

Conversation

jeeyyy
Copy link
Contributor

@jeeyyy jeeyyy commented Sep 26, 2018

This PR implements a new WCAG2.1 rule - label content name mismatch

Closes issue:

Reviewer checks

Required fields, to be filled out by PR reviewer(s)

  • Follows the commit message policy, appropriate for next version
  • Has documentation updated, a DU ticket, or requires no documentation change
  • Includes new tests, or was unnecessary
  • Code is reviewed for security by: << Name here >>

@jeeyyy jeeyyy requested a review from a team as a code owner September 26, 2018 08:33
@jeeyyy jeeyyy changed the title feat: new rule - label content name mismatch feat(rule): label content name mismatch Sep 26, 2018
.toLowerCase()
.trim();
}
if (elm.getAttribute('aria-labelledby')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

aria-labelledby is an element reference. You're just picking up the ID of the element, not the actual text. We have some code for this, but its not isolated properly. Let me complete my accessible name update before completing this. One of the things I'm doing there is to create a getAriaLabelledbyName function.

return false;
}

const contentText = node.textContent.toLowerCase().trim();
Copy link
Contributor

Choose a reason for hiding this comment

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

You should use text.sanitize. It takes things like double spaces into account as well. Related question, does textContent solve for HTML entities like &nbsp;? We should probably have a test that makes sure HTML Entities aren't seen as different characters.

}

const contentText = node.textContent.toLowerCase().trim();
// if no text content - fail
Copy link
Contributor

Choose a reason for hiding this comment

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

Why wouldn't we ignore these types of elements?

"matches": "label-content-name-mismatch-matches.js",
"tags": [
"wcag21a",
"wcag253"
Copy link
Contributor

Choose a reason for hiding this comment

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

We should make this rule experimental for the time being. I don't trust that this isn't going to give false positives.

"impact": "serious",
"messages": {
"pass": "Interactive element contains visible label as part of it's accessible name",
"fail": "Interactive element does not contain visible label as part of it's accessible name"
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest: The visible text of the element is different from its accessible name

assert.isFalse(actual);
});

it('returns false when element has an empty aria-labelledby', function() {
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, empty aria-labelledby will be ignored by the name computation. This shouldn't fail.

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 comment as above, repeating:

getAriaLabelledbyText authored for accessible name computation, does not take that into account, and does not return the content as text :/.

Perhaps the accessible name computation should take this into consideration. Correct me if I am wrong.


it('returns false when element has no text content', function() {
fixture.innerHTML =
'<button id="target" name="link" aria-label="Ok"></button>';
Copy link
Contributor

Choose a reason for hiding this comment

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

This too, if there is no content, there is no mismatch and so this shouldn't fail.

var actual = check.evaluate(node, options, vNode);
assert.isFalse(actual);
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

You're missing quite a few tests here:

  • aria-labelledby with reference to an element that matches / that doesn't match
  • aria-labelledby with references to multiple elements
  • aria-labelledby with references to non-existing elements
  • Elements with hidden texts like: `? help
  • Elements with ASCII as non-text content <button aria-label="close">X</button>
  • ...

@@ -0,0 +1,87 @@
describe('label-content-name-mismatch-matches', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

var actual = rule.matches(target);
assert.isFalse(actual);
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Need tests for aria-labelledby.

@jeeyyy jeeyyy changed the title feat(rule): label content name mismatch [WIP] feat(rule): label content name mismatch Sep 27, 2018
@jeeyyy
Copy link
Contributor Author

jeeyyy commented Oct 4, 2018

Dependency on - #1163
Closing until the above is merged.

@jeeyyy jeeyyy closed this Oct 4, 2018
@jeeyyy jeeyyy reopened this Oct 28, 2018
@jeankaplansky
Copy link
Contributor

Help/Description for Jey

@jeeyyy
Copy link
Contributor Author

jeeyyy commented Nov 1, 2018

Dependency on - #1163
Closing until the above is resolved.

@jeeyyy jeeyyy closed this Nov 1, 2018
@jeeyyy jeeyyy deleted the rule-label-content-name-mismatch branch February 20, 2019 18:59
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.

3 participants