Sha256: bbaa3c73599b5dea0bc84e066e5865e016df9e1bd0193ed1abf9e7bfe2186469

Contents?: true

Size: 1.78 KB

Versions: 104

Compression:

Stored size: 1.78 KB

Contents

/* global text, dom, axe */

/**
 * Returns the visible text of the virtual node
 * NOTE: when calculating the text or accessible text of a node that includes shadow
 * roots attached to it or its children, the flattened tree must be considered
 * rather than the "light DOM"
 * @method visibleVirtual
 * @memberof axe.commons.text
 * @instance
 * @param  {VirtualNode} element
 * @param  {Boolean} screenReader When provided, will evaluate visibility from the perspective of a screen reader
 * @param  {Boolean} noRecursing When False, the result will contain text from the element and it's children.
 * When True, the result will only contain text from the element
 * @return {String}
 */
text.visibleVirtual = function(element, screenReader, noRecursing) {
	const result = element.children
		.map(child => {
			if (child.actualNode.nodeType === 3) {
				// filter on text nodes
				const nodeValue = child.actualNode.nodeValue;
				if (nodeValue && dom.isVisible(element.actualNode, screenReader)) {
					return nodeValue;
				}
			} else if (!noRecursing) {
				return text.visibleVirtual(child, screenReader);
			}
		})
		.join('');
	return text.sanitize(result);
};

/**
 * Finds virtual node and calls visibleVirtual()
 * IMPORTANT: This method requires the composed tree at axe._tree
 * @param  {Element} element
 * @param  {Boolean} screenReader When provided, will evaluate visibility from the perspective of a screen reader
 * @param  {Boolean} noRecursing When False, the result will contain text from the element and it's children.
 * When True, the result will only contain text from the element
 * @return {String}
 */
text.visible = function(element, screenReader, noRecursing) {
	element = axe.utils.getNodeFromTree(axe._tree[0], element);
	return text.visibleVirtual(element, screenReader, noRecursing);
};

Version data entries

104 entries across 104 versions & 1 rubygems

Version Path
govuk_publishing_components-20.0.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-19.0.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-18.3.1 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-18.3.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-18.2.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-18.1.2 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-18.1.1 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-18.0.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.21.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.20.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.19.1 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.19.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.18.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.17.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.16.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.15.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.14.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.13.0 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.12.2 node_modules/axe-core/lib/commons/text/visible-virtual.js
govuk_publishing_components-17.12.1 node_modules/axe-core/lib/commons/text/visible-virtual.js