File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -114,7 +114,12 @@ export class MenuItem {
114114 getAriaLabel ( ) : string {
115115 // This fallback should only be hit by Context Menu items as all
116116 // FieldDropdown options should have an ARIA label.
117- return this . ariaLabel || String ( this . content ) ;
117+ return (
118+ this . ariaLabel ||
119+ ( typeof this . content === 'string'
120+ ? this . content
121+ : this . content . textContent )
122+ ) ;
118123 }
119124
120125 /** Dispose of this menu item. */
Original file line number Diff line number Diff line change @@ -173,4 +173,14 @@ suite('Menu items', function () {
173173 this . menuItem . performAction ( new Event ( 'click' ) ) ;
174174 assert . isTrue ( called ) ;
175175 } ) ;
176+
177+ test ( 'return accurate ARIA labels for HTML elements' , function ( ) {
178+ const div = document . createElement ( 'div' ) ;
179+ const nestedDiv = document . createElement ( 'div' ) ;
180+ nestedDiv . textContent = 'nested' ;
181+ div . textContent = 'test' ;
182+ div . appendChild ( nestedDiv ) ;
183+ const testMenuItem = new Blockly . MenuItem ( div ) ;
184+ assert . equal ( testMenuItem . getAriaLabel ( ) , 'testnested' ) ;
185+ } ) ;
176186} ) ;
You can’t perform that action at this time.
0 commit comments