mirror of
https://github.com/google/blockly.git
synced 2026-05-20 02:50:12 +02:00
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:
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user