@@ -243,76 +243,81 @@ export class BlockSvg
243243 }
244244
245245 computeAriaLabel ( verbose : boolean = false ) : string {
246- const { commaSeparatedSummary, inputCount} = buildBlockSummary (
247- this ,
248- verbose ,
249- ) ;
250- let inputSummary = '' ;
251- if ( inputCount > 1 ) {
252- inputSummary = 'has inputs' ;
253- } else if ( inputCount === 1 ) {
254- inputSummary = 'has input' ;
255- }
246+ const labelComponents = [ ] ;
256247
257- let blockTypeText = 'block' ;
258- if ( this . isShadow ( ) ) {
259- blockTypeText = 'replaceable block' ;
260- } else if ( this . outputConnection ) {
261- blockTypeText = 'input block' ;
262- } else if ( this . statementInputCount ) {
263- blockTypeText = 'C-shaped block' ;
248+ if ( ! this . workspace . isFlyout && this . getRootBlock ( ) === this ) {
249+ labelComponents . push ( 'Begin stack' ) ;
264250 }
265251
266- const modifiers = [ ] ;
267- if ( ! this . isEnabled ( ) ) {
268- modifiers . push ( 'disabled' ) ;
269- }
270- if ( this . isCollapsed ( ) ) {
271- modifiers . push ( 'collapsed' ) ;
272- }
273- if ( modifiers . length ) {
274- blockTypeText = `${ modifiers . join ( ' ' ) } ${ blockTypeText } ` ;
275- }
276-
277- let prefix = '' ;
278252 const parentInput = (
279253 this . previousConnection ?? this . outputConnection
280254 ) ?. targetConnection ?. getParentInput ( ) ;
281255 if ( parentInput && parentInput . type === inputTypes . STATEMENT ) {
282- prefix = `Begin ${ parentInput . getFieldRowLabel ( ) } , ` ;
256+ labelComponents . push ( `Begin ${ parentInput . getFieldRowLabel ( ) } ` ) ;
283257 } else if (
284258 parentInput &&
285259 parentInput . type === inputTypes . VALUE &&
286260 this . getParent ( ) ?. statementInputCount
287261 ) {
288- prefix = `${ parentInput . getFieldRowLabel ( ) } ` ;
262+ labelComponents . push ( `${ parentInput . getFieldRowLabel ( ) } ` ) ;
289263 }
290264
291- if ( this . getRootBlock ( ) === this ) {
292- prefix = 'Begin stack, ' + prefix ;
265+ const { commaSeparatedSummary, inputCount} = buildBlockSummary (
266+ this ,
267+ verbose ,
268+ ) ;
269+ labelComponents . push ( commaSeparatedSummary ) ;
270+
271+ if ( ! this . isEnabled ( ) ) {
272+ labelComponents . push ( 'disabled' ) ;
273+ }
274+ if ( this . isCollapsed ( ) ) {
275+ labelComponents . push ( 'collapsed' ) ;
293276 }
294277
295- let additionalInfo = blockTypeText ;
296- if ( inputSummary ) {
297- additionalInfo = `${ additionalInfo } , ${ inputSummary } ` ;
278+ if ( inputCount > 1 ) {
279+ labelComponents . push ( 'has inputs' ) ;
280+ } else if ( inputCount === 1 ) {
281+ labelComponents . push ( 'has input' ) ;
298282 }
299283
300- return prefix + commaSeparatedSummary + ', ' + additionalInfo ;
284+ return labelComponents . join ( ', ' ) ;
301285 }
302286
303287 private computeAriaRole ( ) {
304288 if ( this . workspace . isFlyout ) {
305289 aria . setRole ( this . pathObject . svgPath , aria . Role . TREEITEM ) ;
306290 } else {
291+ const roleDescription = this . getAriaRoleDescription ( ) ;
307292 aria . setState (
308293 this . pathObject . svgPath ,
309294 aria . State . ROLEDESCRIPTION ,
310- 'block' ,
295+ roleDescription ,
311296 ) ;
312297 aria . setRole ( this . pathObject . svgPath , aria . Role . FIGURE ) ;
313298 }
314299 }
315300
301+ /**
302+ * Returns the ARIA role description for this block.
303+ *
304+ * Block definitions may override this method via a mixin to customize
305+ * their role description.
306+ *
307+ * @returns The ARIA roledescription for this block.
308+ */
309+ protected getAriaRoleDescription ( ) {
310+ if ( this . isShadow ( ) ) {
311+ return 'replaceable block' ;
312+ } else if ( this . outputConnection ) {
313+ return 'value block' ;
314+ } else if ( this . statementInputCount ) {
315+ return 'container block' ;
316+ } else {
317+ return 'statement block' ;
318+ }
319+ }
320+
316321 /**
317322 * Create and initialize the SVG representation of the block.
318323 * May be called more than once.
0 commit comments