Skip to content

Commit

Permalink
use utility function in aria-tooltip-name
Browse files Browse the repository at this point in the history
Co-authored-by: Michiel Pauw <[email protected]>
Co-authored-by: onkar75 <[email protected]>
  • Loading branch information
3 people committed Jun 25, 2024
1 parent 910c0fd commit 2f21d47
Showing 1 changed file with 1 addition and 26 deletions.
27 changes: 1 addition & 26 deletions src/rules/aria-tooltip-name.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,11 @@
import { AccessibilityError } from "../scanner";
import { labelledByIsValid, querySelectorAll } from "../utils";
import { hasAccessibleText, querySelectorAll } from "../utils";

// 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`;

/**
* 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;
}

export function ariaTooltipName(el: Element): AccessibilityError[] {
const errors = [];
const tooltips = querySelectorAll("[role=tooltip]", el);
Expand Down

0 comments on commit 2f21d47

Please sign in to comment.