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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement aria-tooltip-name rule #35

Merged
merged 1 commit into from
Jun 19, 2024
Merged

Implement aria-tooltip-name rule #35

merged 1 commit into from
Jun 19, 2024

Conversation

koddsson
Copy link
Owner

No description provided.

Co-authored-by: Michiel Pauw <[email protected]>
Co-authored-by: onkar75 <[email protected]>
@koddsson koddsson enabled auto-merge (squash) June 19, 2024 07:15
Comment on lines +9 to +32
/**
* Make sure that a elements text is "visible" to a screenreader user.
*
* - Inner text that is discernible to screen reader users.
* - Non-empty aria-label attribute.
* - aria-labelledby pointing to element with text which is discernible to screen reader users.
*/
function hasAccessibleText(el: Element): boolean {
if (el.hasAttribute("aria-label")) {
return el.getAttribute("aria-label")!.trim() !== "";
}

if (!labelledByIsValid(el)) return false;

if (el.getAttribute("title")) {
return el.getAttribute("title")!.trim() !== "";
}

if (el.textContent) {
return el.textContent.trim() !== "";
}

return true;
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

This could probably be extracted out as a utility as I imagine that other rules implement this pattern often as well.

Comment on lines +4 to +7
// Metadata
const id = "aria-tooltip-name";
const text = "ARIA tooltip must have an accessible name";
const url = `https://dequeuniversity.com/rules/axe/4.4/${id}?application=RuleDescription`;
Copy link
Owner Author

@koddsson koddsson Jun 19, 2024

Choose a reason for hiding this comment

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

At some point we should standardise how this metadata is recorded and exposed.

Comment on lines +36 to +37
const tooltips = querySelectorAll("[role=tooltip]", el);
if (el.matches("[role=tooltip]")) tooltips.push(el);
Copy link
Owner Author

Choose a reason for hiding this comment

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

This pattern is pretty universal and easy to forget to match the element that's passed into the rule. Maybe we can abstract that away?

Copy link

LCOV of commit ff6c1ce during CI #121

	(use "lcov --ignore-errors deprecated,deprecated ..." to suppress this warning)
Reading tracefile /var/folders/dm/88b38gj92jj53dgxdsm12qf00000gn/T/__koddsson_github-actions-report-lcov/lcov.info.
Summary coverage rate:
  source files: 25
  lines.......: 90.2% (1314 of 1456 lines)
  functions...: 90.5% (38 of 42 functions)
  branches....: 92.9% (299 of 322 branches)
Message summary:
  1 warning message:
    deprecated: 1

Files changed coverage rate:
  	(use "lcov --ignore-errors deprecated,deprecated ..." to suppress this warning)
                                    |Lines       |Functions  |Branches    
  Filename                          |Rate     Num|Rate    Num|Rate     Num
  src/rules/aria-tooltip-name.ts    |35.4%     48| 0.0%     2|    -      0

@koddsson koddsson merged commit f093731 into main Jun 19, 2024
2 checks passed
Comment on lines +7 to +33
const passes = [
`<div role="tooltip" id="al" aria-label="Name"></div>`,
`<div>
<div role="tooltip" id="alb" aria-labelledby="labeldiv"></div>
<div id="labeldiv">Hello world!</div>
</div>`,
`<div role="tooltip" id="combo" aria-label="Aria Name">Name</div>`,
`<div role="tooltip" id="title" title="Title"></div>`,
];

const violations = [
`<div role="tooltip" id="empty"></div>`,
`<div role="tooltip" id="alempty" aria-label=""></div>`,
`<div
role="tooltip"
id="albmissing"
aria-labelledby="nonexistent"
></div>`,
`<div>
<div role="tooltip" id="albempty" aria-labelledby="emptydiv"></div>
<div id="emptydiv"></div>
</div>`,
];

describe("aria-tooltip-name", async function () {
for (const markup of passes) {
const el = await fixture(html`${markup}`);
Copy link
Owner Author

Choose a reason for hiding this comment

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

We should change all the other rules to use this pattern so that the markup is correct for each rule. Otherwise it's all rendered into memory and then wiped from the DOM after the first test runs.

Copy link
Owner Author

Choose a reason for hiding this comment

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

In fact, standardising this whole suite might be the way to go. A developer should then just provide the test cases.

@koddsson koddsson deleted the aria-tooltip-name branch June 19, 2024 07:28
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.

None yet

1 participant