From f682607a6c8759cade7f66261db580030601198d Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Fri, 12 Sep 2025 14:25:33 -0700 Subject: [PATCH] fix: Use field ARIA labels for field-only blocks. (#9361) * fix: Use field ARIA labels for field-only blocks. * chore: Make the linter happy. --- core/block_svg.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/core/block_svg.ts b/core/block_svg.ts index d90e1ad2a..295b80696 100644 --- a/core/block_svg.ts +++ b/core/block_svg.ts @@ -224,9 +224,6 @@ export class BlockSvg this.currentConnectionCandidate = null; this.doInit_(); - - // Note: This must be done after initialization of the block's fields. - this.recomputeAriaLabel(); } private recomputeAriaLabel() { @@ -239,15 +236,19 @@ export class BlockSvg private computeAriaLabel(): string { // Guess the block's aria label based on its field labels. - if (this.isShadow()) { + if (this.isShadow() || this.isSimpleReporter()) { // TODO: Shadows may have more than one field. // Shadow blocks are best represented directly by their field since they // effectively operate like a field does for keyboard navigation purposes. const field = Array.from(this.getFields())[0]; - return ( - aria.getState(field.getFocusableElement(), aria.State.LABEL) ?? - 'Unknown?' - ); + try { + return ( + aria.getState(field.getFocusableElement(), aria.State.LABEL) ?? + 'Unknown?' + ); + } catch { + return 'Unknown?'; + } } const fieldLabels = []; @@ -306,6 +307,8 @@ export class BlockSvg if (!svg.parentNode) { this.workspace.getCanvas().appendChild(svg); } + // Note: This must be done after initialization of the block's fields. + this.recomputeAriaLabel(); this.initialized = true; }