Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions packages/blockly/core/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import type {
IVariableModel,
IVariableState,
} from './interfaces/i_variable_model.js';
import {Msg} from './msg.js';
import * as registry from './registry.js';
import * as Tooltip from './tooltip.js';
import * as arrayUtils from './utils/array.js';
Expand Down Expand Up @@ -1567,15 +1568,27 @@ export class Block {
}

/**
* @returns The custom string to use as the role description for this block,
* or undefined if no custom description is set.
* @returns The string to use as the role description for this block. If a
* custom provider has been set, use that. Otherwise, return a default
* description based on the block's properties.
*/
getAriaRoleDescription(): string | undefined {
if (!this.ariaRoleDescriptionProvider) return undefined;
if (typeof this.ariaRoleDescriptionProvider === 'function') {
return this.ariaRoleDescriptionProvider();
getAriaRoleDescription(): string {
if (this.ariaRoleDescriptionProvider) {
if (typeof this.ariaRoleDescriptionProvider === 'function') {
return this.ariaRoleDescriptionProvider();
}
return replaceMessageReferences(this.ariaRoleDescriptionProvider);
}

let roleDescription: string;
if (this.statementInputCount) {
roleDescription = Msg['BLOCK_LABEL_CONTAINER'];
} else if (this.outputConnection) {
roleDescription = Msg['BLOCK_LABEL_VALUE'];
} else {
roleDescription = Msg['BLOCK_LABEL_STATEMENT'];
}
return replaceMessageReferences(this.ariaRoleDescriptionProvider);
return roleDescription;
}

/**
Expand Down
18 changes: 6 additions & 12 deletions packages/blockly/core/block_aria_composer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export function computeAriaLabel(
verbosity >= Verbosity.STANDARD && getCollapsedLabel(block),
verbosity >= Verbosity.LOQUACIOUS && getShadowBlockLabel(block),
verbosity >= Verbosity.STANDARD && getInputCountLabel(block),
verbosity >= Verbosity.LOQUACIOUS && block.getAriaRoleDescription(),
]
.filter((label) => !!label)
.join(', ');
Expand All @@ -100,18 +101,11 @@ export function configureAriaRole(block: BlockSvg) {
setRole(focusableElement, Role.FIGURE);
}

let roleDescription;
const customDescription = block.getAriaRoleDescription();
if (customDescription) {
roleDescription = customDescription;
} else if (block.statementInputCount) {
roleDescription = Msg['BLOCK_LABEL_CONTAINER'];
} else if (block.outputConnection) {
roleDescription = Msg['BLOCK_LABEL_VALUE'];
} else {
roleDescription = Msg['BLOCK_LABEL_STATEMENT'];
}
setState(focusableElement, State.ROLEDESCRIPTION, roleDescription);
setState(
focusableElement,
State.ROLEDESCRIPTION,
block.getAriaRoleDescription(),
);
}

/**
Expand Down
Loading