Skip to content

Commit f682607

Browse files
authored
fix: Use field ARIA labels for field-only blocks. (#9361)
* fix: Use field ARIA labels for field-only blocks. * chore: Make the linter happy.
1 parent b10f1af commit f682607

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

core/block_svg.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,6 @@ export class BlockSvg
224224
this.currentConnectionCandidate = null;
225225

226226
this.doInit_();
227-
228-
// Note: This must be done after initialization of the block's fields.
229-
this.recomputeAriaLabel();
230227
}
231228

232229
private recomputeAriaLabel() {
@@ -239,15 +236,19 @@ export class BlockSvg
239236

240237
private computeAriaLabel(): string {
241238
// Guess the block's aria label based on its field labels.
242-
if (this.isShadow()) {
239+
if (this.isShadow() || this.isSimpleReporter()) {
243240
// TODO: Shadows may have more than one field.
244241
// Shadow blocks are best represented directly by their field since they
245242
// effectively operate like a field does for keyboard navigation purposes.
246243
const field = Array.from(this.getFields())[0];
247-
return (
248-
aria.getState(field.getFocusableElement(), aria.State.LABEL) ??
249-
'Unknown?'
250-
);
244+
try {
245+
return (
246+
aria.getState(field.getFocusableElement(), aria.State.LABEL) ??
247+
'Unknown?'
248+
);
249+
} catch {
250+
return 'Unknown?';
251+
}
251252
}
252253

253254
const fieldLabels = [];
@@ -306,6 +307,8 @@ export class BlockSvg
306307
if (!svg.parentNode) {
307308
this.workspace.getCanvas().appendChild(svg);
308309
}
310+
// Note: This must be done after initialization of the block's fields.
311+
this.recomputeAriaLabel();
309312
this.initialized = true;
310313
}
311314

0 commit comments

Comments
 (0)