fix: remove redundant labels for child blocks of parent input (#9967)

* fix: remove redundant labels for child blocks of parent input

* chore: make new argument optional
This commit is contained in:
Michael Harvey
2026-06-10 13:28:25 -04:00
committed by GitHub
parent 0b43cb312d
commit e22287ec39
3 changed files with 31 additions and 13 deletions
+22 -8
View File
@@ -205,6 +205,9 @@ export function computeFieldRowLabel(
* wrapped in the "Begin %1" prefix so the readout indicates that the child
* block starts the body of the statement input.
*
* Labels for child blocks of inputs are excluded because they are included
* with {@link getInputLabels} already.
*
* @internal
* @param block The block to generate a parent input label for.
* @returns A description of the block's parent statement input, or undefined
@@ -242,6 +245,7 @@ function getParentInputLabel(block: BlockSvg) {
const sectionLabels = getInputLabelsSubset(
parentBlock as BlockSvg,
parentInput,
false, // Exclude labels from child blocks.
);
if (!sectionLabels.length) {
return undefined;
@@ -338,17 +342,23 @@ export function getInputLabels(
*
* @internal
* @param block The block to retrieve a list of field/input labels for.
* @param input The input that defines the end of the subset.
* @param endInput The input that defines the end of the subset.
* @param includeEndInputChildren Whether to include labels for child blocks
* connected to the end input.
* @returns A list of field/input labels for the given block.
*/
export function getInputLabelsSubset(block: BlockSvg, input: Input): string[] {
const inputIndex = block.inputList.indexOf(input);
export function getInputLabelsSubset(
block: BlockSvg,
endInput: Input,
includeEndInputChildren: boolean,
): string[] {
const inputIndex = block.inputList.indexOf(endInput);
if (inputIndex === -1) {
throw new Error(
`Input with name "${input.name}" not found on block with id "${block.id}".`,
`Input with name "${endInput.name}" not found on block with id "${block.id}".`,
);
}
const isStatementTarget = input.type === inputTypes.STATEMENT;
const isStatementTarget = endInput.type === inputTypes.STATEMENT;
const startIndex = isStatementTarget
? findStartOfStatementSection(block.inputList, inputIndex)
@@ -362,9 +372,13 @@ export function getInputLabelsSubset(block: BlockSvg, input: Input): string[] {
.filter((subsetInput) => subsetInput.isVisible());
// The derived labels are based on the field row and any connected child
// blocks.
// blocks. Labels for child blocks are potentially skipped if they would be
// redundant within the overall block label.
const derivedLabels = inputsInSubset.map((subsetInput) =>
subsetInput.getLabel(Verbosity.TERSE),
subsetInput.getLabel(
Verbosity.TERSE,
subsetInput !== endInput || includeEndInputChildren,
),
);
// For statement inputs, we only include the fallback label ("input %1")
@@ -529,7 +543,7 @@ function computeMoveConnectionLabel(
let inputLabel = input.getAriaLabelText();
if (!inputLabel) {
const labels = getInputLabelsSubset(conn.getSourceBlock(), input);
const labels = getInputLabelsSubset(conn.getSourceBlock(), input, true);
if (!labels.length) return baseLabel;
inputLabel = labels.join(', ');
+8 -5
View File
@@ -400,18 +400,21 @@ export class Input {
/**
* Returns a derived accessibility label for this input: field row text plus
* labels of any connected child blocks. Does not include custom labels from
* {@link getAriaLabelText}; those are used in move-mode and parent-input
* context only.
* labels of any connected child blocks (unless excluded). Does not include
* custom labels from {@link getAriaLabelText}; those are used in move-mode
* and parent-input context only.
*
* @internal
*/
getLabel(verbosity = Verbosity.STANDARD): string {
getLabel(verbosity = Verbosity.STANDARD, includeChildren = true): string {
if (!this.isVisible()) return '';
const labels = computeFieldRowLabel(this, false, verbosity);
if (this.connection?.type === ConnectionType.INPUT_VALUE) {
if (
includeChildren &&
this.connection?.type === ConnectionType.INPUT_VALUE
) {
const childBlock = this.connection.targetBlock();
if (childBlock && !childBlock.isInsertionMarker()) {
labels.push(
@@ -360,6 +360,7 @@ export class RenderedConnection
getInputLabelsSubset(
parentInput.getSourceBlock() as BlockSvg,
parentInput,
true,
).join(', ');
if (this.type === ConnectionType.NEXT_STATEMENT) {
aria.setState(