Sha256: 9a00150f282a3853008986668fcdd301425961d7738e5f4c322699b6ffbcd192

Contents?: true

Size: 1.23 KB

Versions: 11

Compression:

Stored size: 1.23 KB

Contents

/**
 * Determine whether an element is visible
 * @method isHidden
 * @memberof axe.utils
 * @param {HTMLElement} el The HTMLElement
 * @param {Boolean} recursed
 * @return {Boolean} The element's visibilty status
 */
axe.utils.isHidden = function isHidden(el, recursed) {
	'use strict';
	const node = axe.utils.getNodeFromTree(el);

	// 9 === Node.DOCUMENT
	if (el.nodeType === 9) {
		return false;
	}

	// 11 === Node.DOCUMENT_FRAGMENT_NODE
	if (el.nodeType === 11) {
		el = el.host; // grab the host Node
	}

	if (node && node._isHidden !== null) {
		return node._isHidden;
	}

	const style = window.getComputedStyle(el, null);

	if (
		!style ||
		(!el.parentNode ||
			(style.getPropertyValue('display') === 'none' ||
				(!recursed &&
					// visibility is only accurate on the first element
					style.getPropertyValue('visibility') === 'hidden') ||
				el.getAttribute('aria-hidden') === 'true'))
	) {
		return true;
	}

	const parent = el.assignedSlot ? el.assignedSlot : el.parentNode;
	const isHidden = axe.utils.isHidden(parent, true);

	// cache the results of the isHidden check on the parent tree
	// so we don't have to look at the parent tree again for all its
	// descendants
	if (node) {
		node._isHidden = isHidden;
	}

	return isHidden;
};

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
govuk_publishing_components-21.22.1 node_modules/axe-core/lib/core/utils/is-hidden.js
govuk_publishing_components-21.22.0 node_modules/axe-core/lib/core/utils/is-hidden.js
govuk_publishing_components-21.21.3 node_modules/axe-core/lib/core/utils/is-hidden.js
govuk_publishing_components-21.21.2 node_modules/axe-core/lib/core/utils/is-hidden.js
govuk_publishing_components-21.21.1 node_modules/axe-core/lib/core/utils/is-hidden.js
govuk_publishing_components-21.21.0 node_modules/axe-core/lib/core/utils/is-hidden.js
govuk_publishing_components-21.20.0 node_modules/axe-core/lib/core/utils/is-hidden.js
govuk_publishing_components-21.19.1 node_modules/axe-core/lib/core/utils/is-hidden.js
govuk_publishing_components-21.19.0 node_modules/axe-core/lib/core/utils/is-hidden.js
govuk_publishing_components-21.18.0 node_modules/axe-core/lib/core/utils/is-hidden.js
govuk_publishing_components-21.17.0 node_modules/axe-core/lib/core/utils/is-hidden.js