mirror of
https://github.com/google/blockly.git
synced 2026-01-11 02:47:09 +01:00
fix: Use field ARIA labels for field-only blocks. (#9361)
* fix: Use field ARIA labels for field-only blocks. * chore: Make the linter happy.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user