@@ -226,7 +226,17 @@ export class BlockSvg
226226 this . computeAriaRole ( ) ;
227227 }
228228
229- private recomputeAriaLabel ( ) {
229+ /**
230+ * Updates the ARIA label of this block to reflect its current configuration.
231+ *
232+ * @internal
233+ */
234+ recomputeAriaLabel ( ) {
235+ if ( this . isSimpleReporter ( ) ) {
236+ const field = Array . from ( this . getFields ( ) ) [ 0 ] ;
237+ if ( field . isFullBlockField ( ) && field . isCurrentlyEditable ( ) ) return ;
238+ }
239+
230240 aria . setState (
231241 this . getFocusableElement ( ) ,
232242 aria . State . LABEL ,
@@ -240,34 +250,42 @@ export class BlockSvg
240250 ? ` ${ inputCount } ${ inputCount > 1 ? 'inputs' : 'input' } `
241251 : '' ;
242252
243- let currentBlock : Block | null = null ;
253+ let currentBlock : BlockSvg | null = null ;
244254 let nestedStatementBlockCount = 0 ;
245- // This won't work well for if/else blocks.
246- this . inputList . forEach ( ( input ) => {
255+
256+ for ( const input of this . inputList ) {
247257 if (
248258 input . connection &&
249259 input . connection . type === ConnectionType . NEXT_STATEMENT
250260 ) {
251- currentBlock = input . connection . targetBlock ( ) ;
261+ currentBlock = input . connection . targetBlock ( ) as BlockSvg | null ;
262+ while ( currentBlock ) {
263+ nestedStatementBlockCount ++ ;
264+ currentBlock = currentBlock . getNextBlock ( ) ;
265+ }
252266 }
253- } ) ;
254- // The type is poorly inferred here.
255- while ( currentBlock as Block | null ) {
256- nestedStatementBlockCount ++ ;
257- // The type is poorly inferred here.
258- // If currentBlock is null, we can't enter this while loop...
259- currentBlock = currentBlock ! . getNextBlock ( ) ;
260267 }
261268
262269 let blockTypeText = 'block' ;
263270 if ( this . isShadow ( ) ) {
264- blockTypeText = 'input block' ;
265- } else if ( this . outputConnection ) {
266271 blockTypeText = 'replacable block' ;
272+ } else if ( this . outputConnection ) {
273+ blockTypeText = 'input block' ;
267274 } else if ( this . statementInputCount ) {
268275 blockTypeText = 'C-shaped block' ;
269276 }
270277
278+ const modifiers = [ ] ;
279+ if ( ! this . isEnabled ( ) ) {
280+ modifiers . push ( 'disabled' ) ;
281+ }
282+ if ( this . isCollapsed ( ) ) {
283+ modifiers . push ( 'collapsed' ) ;
284+ }
285+ if ( modifiers . length ) {
286+ blockTypeText = `${ modifiers . join ( ' ' ) } ${ blockTypeText } ` ;
287+ }
288+
271289 let prefix = '' ;
272290 const parentInput = (
273291 this . previousConnection ?? this . outputConnection
@@ -298,9 +316,7 @@ export class BlockSvg
298316 }
299317
300318 private computeAriaRole ( ) {
301- if ( this . isSimpleReporter ( ) ) {
302- aria . setRole ( this . pathObject . svgPath , aria . Role . BUTTON ) ;
303- } else if ( this . workspace . isFlyout ) {
319+ if ( this . workspace . isFlyout ) {
304320 aria . setRole ( this . pathObject . svgPath , aria . Role . TREEITEM ) ;
305321 } else {
306322 aria . setState (
@@ -335,8 +351,6 @@ export class BlockSvg
335351 if ( ! svg . parentNode ) {
336352 this . workspace . getCanvas ( ) . appendChild ( svg ) ;
337353 }
338- // Note: This must be done after initialization of the block's fields.
339- this . recomputeAriaLabel ( ) ;
340354 this . initialized = true ;
341355 }
342356
@@ -672,6 +686,7 @@ export class BlockSvg
672686 this . removeInput ( collapsedInputName ) ;
673687 dom . removeClass ( this . svgGroup , 'blocklyCollapsed' ) ;
674688 this . setWarningText ( null , BlockSvg . COLLAPSED_WARNING_ID ) ;
689+ this . recomputeAriaLabel ( ) ;
675690 return ;
676691 }
677692
@@ -693,6 +708,8 @@ export class BlockSvg
693708 this . getInput ( collapsedInputName ) ||
694709 this . appendDummyInput ( collapsedInputName ) ;
695710 input . appendField ( new FieldLabel ( text ) , collapsedFieldName ) ;
711+
712+ this . recomputeAriaLabel ( ) ;
696713 }
697714
698715 /**
@@ -1108,6 +1125,8 @@ export class BlockSvg
11081125 for ( const child of this . getChildren ( false ) ) {
11091126 child . updateDisabled ( ) ;
11101127 }
1128+
1129+ this . recomputeAriaLabel ( ) ;
11111130 }
11121131
11131132 /**
@@ -1752,8 +1771,6 @@ export class BlockSvg
17521771 * settings.
17531772 */
17541773 render ( ) {
1755- this . recomputeAriaLabel ( ) ;
1756-
17571774 this . queueRender ( ) ;
17581775 renderManagement . triggerQueuedRenders ( ) ;
17591776 }
@@ -1765,8 +1782,6 @@ export class BlockSvg
17651782 * @internal
17661783 */
17671784 renderEfficiently ( ) {
1768- this . recomputeAriaLabel ( ) ;
1769-
17701785 dom . startTextWidthCache ( ) ;
17711786
17721787 if ( this . isCollapsed ( ) ) {
@@ -1948,6 +1963,12 @@ export class BlockSvg
19481963
19491964 /** See IFocusableNode.getFocusableElement. */
19501965 getFocusableElement ( ) : HTMLElement | SVGElement {
1966+ if ( this . isSimpleReporter ( ) ) {
1967+ const field = Array . from ( this . getFields ( ) ) [ 0 ] ;
1968+ if ( field && field . isFullBlockField ( ) && field . isCurrentlyEditable ( ) ) {
1969+ return field . getFocusableElement ( ) ;
1970+ }
1971+ }
19511972 return this . pathObject . svgPath ;
19521973 }
19531974
@@ -1958,6 +1979,7 @@ export class BlockSvg
19581979
19591980 /** See IFocusableNode.onNodeFocus. */
19601981 onNodeFocus ( ) : void {
1982+ this . recomputeAriaLabel ( ) ;
19611983 this . select ( ) ;
19621984 this . workspace . scrollBoundsIntoView (
19631985 this . getBoundingRectangleWithoutChildren ( ) ,
@@ -2038,6 +2060,7 @@ function buildBlockSummary(block: BlockSvg): BlockSummary {
20382060 return block . inputList
20392061 . flatMap ( ( input ) => {
20402062 const fields = input . fieldRow . map ( ( field ) => {
2063+ if ( ! field . isVisible ( ) ) return [ ] ;
20412064 // If the block is a full block field, we only want to know if it's an
20422065 // editable field if we're not directly on it.
20432066 if ( field . EDITABLE && ! field . isFullBlockField ( ) && ! isNestedInput ) {
@@ -2046,6 +2069,7 @@ function buildBlockSummary(block: BlockSvg): BlockSummary {
20462069 return [ field . getText ( ) ?? field . getValue ( ) ] ;
20472070 } ) ;
20482071 if (
2072+ input . isVisible ( ) &&
20492073 input . connection &&
20502074 input . connection . type === ConnectionType . INPUT_VALUE
20512075 ) {
0 commit comments