Sha256: 5679048c62d70bf7b9d00ec723c909cc4a4714c3f9fec57fcc40641d4a943707
Contents?: true
Size: 1.44 KB
Versions: 104
Compression:
Stored size: 1.44 KB
Contents
/* global dom, text */ /** * Return accessible text for an implicit and/or explicit HTML label element * @param {VirtualNode} element * @param {Object} context * @property {Bool} inControlContext * @property {Bool} inLabelledByContext * @return {String} Label text */ text.labelText = function labelText(virtualNode, context = {}) { const { alreadyProcessed } = text.accessibleTextVirtual if ( context.inControlContext || context.inLabelledByContext || alreadyProcessed(virtualNode, context) ) { return ''; } if (!context.startNode) { context.startNode = virtualNode; } const labelContext = { inControlContext: true, ...context }; const explicitLabels = getExplicitLabels(virtualNode); const implicitLabel = dom.findUpVirtual(virtualNode, 'label'); let labels; if (implicitLabel) { labels = [...explicitLabels, implicitLabel]; labels.sort(axe.utils.nodeSorter); } else { labels = explicitLabels; } return labels .map(label => text.accessibleText(label, labelContext)) .filter(text => text !== '') .join(' '); }; /** * Find a non-ARIA label for an element * @private * @param {VirtualNode} element The VirtualNode instance whose label we are seeking * @return {HTMLElement} The label element, or null if none is found */ function getExplicitLabels({ actualNode }) { if (!actualNode.id) { return []; } return dom.findElmsInContext({ elm: 'label', attr: 'for', value: actualNode.id, context: actualNode }); }
Version data entries
104 entries across 104 versions & 1 rubygems