aria-api

access ARIA information from JavaScript
git clone https://git.ce9e.org/aria-api.git

commit
05e262107906cb6de990b96d22a760a37f124026
parent
27ab3f3c4096a7a6def5e83ee7c91291f50c2f69
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2026-02-18 23:15
name: fix slot order

Diffstat

M lib/name.js 18 +++++++++++-------
M test/test-name.js 14 ++++++++++++++

2 files changed, 25 insertions, 7 deletions


diff --git a/lib/name.js b/lib/name.js

@@ -46,13 +46,17 @@ const getContent = function(root, ongoingLabelledBy, visited) {
   46    46 	for (let i = 0; i < children.length; i++) {
   47    47 		const node = children[i];
   48    48 		if (node.nodeType === node.TEXT_NODE) {
   49    -1 			const styles = window.getComputedStyle(node.parentElement);
   50    -1 			if (styles.textTransform === 'uppercase') {
   51    -1 				ret += node.textContent.toUpperCase();
   52    -1 			} else if (styles.textTransform === 'lowercase') {
   53    -1 				ret += node.textContent.toLowerCase();
   54    -1 			} else if (styles.textTransform === 'capitalize') {
   55    -1 				ret += node.textContent.replace(/\b\w/g, c => c.toUpperCase());
   -1    49 			if (node.parentElement) {
   -1    50 				const styles = window.getComputedStyle(node.parentElement);
   -1    51 				if (styles.textTransform === 'uppercase') {
   -1    52 					ret += node.textContent.toUpperCase();
   -1    53 				} else if (styles.textTransform === 'lowercase') {
   -1    54 					ret += node.textContent.toLowerCase();
   -1    55 				} else if (styles.textTransform === 'capitalize') {
   -1    56 					ret += node.textContent.replace(/\b\w/g, c => c.toUpperCase());
   -1    57 				} else {
   -1    58 					ret += node.textContent;
   -1    59 				}
   56    60 			} else {
   57    61 				ret += node.textContent;
   58    62 			}

diff --git a/test/test-name.js b/test/test-name.js

@@ -14,4 +14,18 @@ describe('getName / getDescription', () => {
   14    14 		var element = document.querySelector('#test');
   15    15 		expect(aria.getName(element)).toBe('test');
   16    16 	});
   -1    17 
   -1    18 	it('processes shadow roots and slots in the correct order', () => {
   -1    19 		testbed.setHTMLUnsafe(`<h1 id="test">
   -1    20 			<host-element>
   -1    21 				<template shadowrootmode="open">
   -1    22 					Such a <slot></slot> thing!
   -1    23 				</template>
   -1    24 				<span>great</span>
   -1    25 			</host-element>
   -1    26 			</h1>
   -1    27 		`);
   -1    28 		var element = document.querySelector('#test');
   -1    29 		expect(aria.getName(element)).toBe('Such a great thing!');
   -1    30 	});
   17    31 });