How to use the axe-core.utils function in axe-core

To help you get started, we’ve selected a few axe-core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / accessibility-insights-web / src / scanner / custom-rules / unique-landmark.ts View on Github external
function evaluate(node: any, options: any): boolean {
    if (isLandmark(node) === false) {
        return false;
    }

    const role = getObservedRoleForElement(node);
    let label = axe.commons.aria.label(node);
    let candidates: Array = [];
    const selectors = getRoleSelectors(role);
    const selectorsLength = selectors.length;
    label = label ? label.toLowerCase() : null;
    // tslint:disable-next-line:no-invalid-this
    this.data({ role: role, label: label });
    for (let selectorPos = 0; selectorPos < selectorsLength; selectorPos++) {
        candidates = candidates.concat(
            axe.utils.toArray(document.querySelectorAll(selectors[selectorPos])),
        );
    }
    const candidatesLength = candidates.length;
    if (candidatesLength > 1) {
        for (let candidatePos = 0; candidatePos < candidatesLength; candidatePos++) {
            const candidate = candidates[candidatePos];
            if (
                candidate !== node &&
                isLandmark(candidate) &&
                axe.commons.dom.isVisible(candidate, true)
            ) {
                let candidateLabel = axe.commons.aria.label(candidate);
                candidateLabel = candidateLabel ? candidateLabel.toLowerCase() : null;
                if (label === candidateLabel) {
                    return false;
                }
github microsoft / accessibility-insights-web / src / scanner / custom-rules / image-rule.ts View on Github external
export function isImage(node: HTMLElement, virtualNode: HTMLElement): boolean {
    const selector: string = 'img, [role=img], svg';
    if (axe.utils.matchesSelector(node, selector)) {
        return true;
    }
    if (node.tagName.toLowerCase() === 'i' && node.innerHTML === '') {
        return true;
    }
    if (AxeUtils.hasBackgoundImage(node)) {
        return true;
    }

    return false;
}