fix: Improve ARIA fallback generation for HTML-based menu items (#9827)

* fix: Improve ARIA fallback generation for HTML-based menu items

* chore: Remove unneeded cast
This commit is contained in:
Aaron Dodson
2026-05-07 13:42:54 -07:00
committed by GitHub
parent 23fcf16440
commit ce8662893c
2 changed files with 16 additions and 1 deletions
+6 -1
View File
@@ -114,7 +114,12 @@ export class MenuItem {
getAriaLabel(): string {
// This fallback should only be hit by Context Menu items as all
// FieldDropdown options should have an ARIA label.
return this.ariaLabel || String(this.content);
return (
this.ariaLabel ||
(typeof this.content === 'string'
? this.content
: this.content.textContent)
);
}
/** Dispose of this menu item. */
@@ -173,4 +173,14 @@ suite('Menu items', function () {
this.menuItem.performAction(new Event('click'));
assert.isTrue(called);
});
test('return accurate ARIA labels for HTML elements', function () {
const div = document.createElement('div');
const nestedDiv = document.createElement('div');
nestedDiv.textContent = 'nested';
div.textContent = 'test';
div.appendChild(nestedDiv);
const testMenuItem = new Blockly.MenuItem(div);
assert.equal(testMenuItem.getAriaLabel(), 'testnested');
});
});