How to use the axe-core.commons 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 dequelabs / color-palette / src / utils / colors.js View on Github external
return backgrounds.reduce((acc, bg) => {
    const bgColor = new axe.commons.color.Color(...bg.rgba);

    texts.filter(fg => fg.hex !== bg.hex).forEach(fg => {
      const fgColor = new axe.commons.color.Color(...fg.rgba);
      const contrast = axe.commons.color.getContrast(bgColor, fgColor);
      // TODO: Account for bold text here
      const cutoff = results.fontSize < 18 ? 4.5 : 3;
      const pass = contrast >= cutoff;
      const suggestedColor =
        !pass &&
        suggestColors(bgColor, fgColor, {
          AA: cutoff
        });
      const suggestion = suggestedColor && suggestedColor['AA'];
      const { rgba, hex } = suggestion && getAllColorTypes(suggestion.fg);

      acc.push({
github dequelabs / color-palette / src / utils / colors.js View on Github external
texts.filter(fg => fg.hex !== bg.hex).forEach(fg => {
      const fgColor = new axe.commons.color.Color(...fg.rgba);
      const contrast = axe.commons.color.getContrast(bgColor, fgColor);
      // TODO: Account for bold text here
      const cutoff = results.fontSize < 18 ? 4.5 : 3;
      const pass = contrast >= cutoff;
      const suggestedColor =
        !pass &&
        suggestColors(bgColor, fgColor, {
          AA: cutoff
        });
      const suggestion = suggestedColor && suggestedColor['AA'];
      const { rgba, hex } = suggestion && getAllColorTypes(suggestion.fg);

      acc.push({
        fg,
        bg,
        contrast,
github microsoft / accessibility-insights-web / src / scanner / custom-rules / css-content-rule.ts View on Github external
function getAllPseudoElements(node: HTMLElement): HTMLElement[] {
    const elements = node.querySelectorAll('*');

    const hasContent = styles => {
        return styles && styles.content !== 'none';
    };

    const pseudoElements = [];
    for (let index = 0; index < elements.length; index++) {
        const element = elements.item(index);
        const beforeStyles = window.getComputedStyle(element, ':before');
        const afterStyles = window.getComputedStyle(element, ':after');

        if (
            axe.commons.dom.isVisible(element) &&
            (hasContent(beforeStyles) || hasContent(afterStyles))
        ) {
            pseudoElements.push(element);
        }
    }

    return pseudoElements;
}
github microsoft / accessibility-insights-web / src / scanner / axe-utils.ts View on Github external
export function getAccessibleText(node: HTMLElement, isLabelledByContext: boolean): string {
    return axe.commons.text.accessibleText(node, isLabelledByContext);
}
github dequelabs / color-palette / src / color-palette.js View on Github external
return combos.map((combo, i) => {
		var fgColor = getColor(combo[0]);
		var bgColor = getColor(combo[1]);
		var contrast = axe.commons.color.getContrast(bgColor, fgColor);
		return 
		
		
		
		
		
			Sample Text
		
		
			{ `${(contrast >= 4.5 ? '\u2714' : '\u2718')}  (${contrast.toFixed(2)}:1)` }
		
		
			{ `${(contrast >= 3.0 ? '\u2714' : '\u2718')}  (${contrast.toFixed(2)}:1)` }
		
      
        { contrast >= 3.0 && contrast < 4.5 ?
github microsoft / accessibility-insights-web / src / scanner / custom-rules / css-positioning-rule.ts View on Github external
function matches(node: HTMLElement): boolean {
    const nodeStyle = window.getComputedStyle(node);
    return (
        axe.commons.dom.isVisible(node) &&
        (isAbsolutePosition(nodeStyle) || isRightFloat(nodeStyle))
    );
}
github dequelabs / color-palette / src / color-palette.js View on Github external
function getColor(hex) {
	const { red, green, blue, alpha } = hexRgb(hex);
	return new axe.commons.color.Color(red, green, blue, alpha/255
	);
}
github microsoft / accessibility-insights-web / src / scanner / custom-rules / unique-landmark.ts View on Github external
role = role ? role.trim() : role;
    if (!role) {
        role = axe.commons.aria.implicitRole(element);
        const tagName = element.tagName.toLowerCase();
        if (tagName === 'header' || tagName === 'footer') {
            let parent = element.parentNode;
            while (parent && parent.nodeType === 1) {
                const parentTagName = parent.tagName.toLowerCase();
                const excludedDescendants = ['article', 'aside', 'main', 'nav', 'section'];
                if (excludedDescendants.indexOf(parentTagName) >= 0) {
                    role = null;
                }
                parent = parent.parentNode;
            }
        } else if (tagName === 'section' || tagName === 'form') {
            const label = axe.commons.aria.label(element);
            if (!label) {
                role = null;
            }
        }
    }
    if (role) {
        role = role.toLowerCase();
    }
    return role;
}
github microsoft / accessibility-insights-web / src / scanner / custom-rules / unique-landmark.ts View on Github external
function isLandmark(element: any): boolean {
    const landmarkRoles = axe.commons.aria.getRolesByType('landmark');
    const role = getObservedRoleForElement(element);

    return (role && landmarkRoles.indexOf(role) >= 0) || role === 'region';
}
github microsoft / accessibility-insights-web / src / scanner / role-utils.ts View on Github external
public static isValidRoleIfPresent(
        node: HTMLElement,
        options?: any,
        virtualNode?: any,
        context?: any,
    ): boolean {
        const role = node.getAttribute('role');
        if (role === null) {
            return true;
        }
        return axe.commons.aria.lookupTable.role[role] !== undefined;
    }
}

axe-core

Accessibility engine for automated Web UI testing

MPL-2.0
Latest version published 29 days ago

Package Health Score

100 / 100
Full package analysis