Skip to content

Commit 000aafd

Browse files
authored
feat: add block role description to verbose block labels (#9960)
1 parent bb8b7a9 commit 000aafd

2 files changed

Lines changed: 26 additions & 19 deletions

File tree

packages/blockly/core/block.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import type {
4646
IVariableModel,
4747
IVariableState,
4848
} from './interfaces/i_variable_model.js';
49+
import {Msg} from './msg.js';
4950
import * as registry from './registry.js';
5051
import * as Tooltip from './tooltip.js';
5152
import * as arrayUtils from './utils/array.js';
@@ -1567,15 +1568,27 @@ export class Block {
15671568
}
15681569

15691570
/**
1570-
* @returns The custom string to use as the role description for this block,
1571-
* or undefined if no custom description is set.
1571+
* @returns The string to use as the role description for this block. If a
1572+
* custom provider has been set, use that. Otherwise, return a default
1573+
* description based on the block's properties.
15721574
*/
1573-
getAriaRoleDescription(): string | undefined {
1574-
if (!this.ariaRoleDescriptionProvider) return undefined;
1575-
if (typeof this.ariaRoleDescriptionProvider === 'function') {
1576-
return this.ariaRoleDescriptionProvider();
1575+
getAriaRoleDescription(): string {
1576+
if (this.ariaRoleDescriptionProvider) {
1577+
if (typeof this.ariaRoleDescriptionProvider === 'function') {
1578+
return this.ariaRoleDescriptionProvider();
1579+
}
1580+
return replaceMessageReferences(this.ariaRoleDescriptionProvider);
1581+
}
1582+
1583+
let roleDescription: string;
1584+
if (this.statementInputCount) {
1585+
roleDescription = Msg['BLOCK_LABEL_CONTAINER'];
1586+
} else if (this.outputConnection) {
1587+
roleDescription = Msg['BLOCK_LABEL_VALUE'];
1588+
} else {
1589+
roleDescription = Msg['BLOCK_LABEL_STATEMENT'];
15771590
}
1578-
return replaceMessageReferences(this.ariaRoleDescriptionProvider);
1591+
return roleDescription;
15791592
}
15801593

15811594
/**

packages/blockly/core/block_aria_composer.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export function computeAriaLabel(
7979
verbosity >= Verbosity.STANDARD && getCollapsedLabel(block),
8080
verbosity >= Verbosity.LOQUACIOUS && getShadowBlockLabel(block),
8181
verbosity >= Verbosity.STANDARD && getInputCountLabel(block),
82+
verbosity >= Verbosity.LOQUACIOUS && block.getAriaRoleDescription(),
8283
]
8384
.filter((label) => !!label)
8485
.join(', ');
@@ -100,18 +101,11 @@ export function configureAriaRole(block: BlockSvg) {
100101
setRole(focusableElement, Role.FIGURE);
101102
}
102103

103-
let roleDescription;
104-
const customDescription = block.getAriaRoleDescription();
105-
if (customDescription) {
106-
roleDescription = customDescription;
107-
} else if (block.statementInputCount) {
108-
roleDescription = Msg['BLOCK_LABEL_CONTAINER'];
109-
} else if (block.outputConnection) {
110-
roleDescription = Msg['BLOCK_LABEL_VALUE'];
111-
} else {
112-
roleDescription = Msg['BLOCK_LABEL_STATEMENT'];
113-
}
114-
setState(focusableElement, State.ROLEDESCRIPTION, roleDescription);
104+
setState(
105+
focusableElement,
106+
State.ROLEDESCRIPTION,
107+
block.getAriaRoleDescription(),
108+
);
115109
}
116110

117111
/**

0 commit comments

Comments
 (0)