Skip to content

Commit 9273d64

Browse files
authored
fix: dont show input number in connection labels (#9940)
1 parent 46ac410 commit 9273d64

3 files changed

Lines changed: 31 additions & 6 deletions

File tree

packages/blockly/core/block_aria_composer.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,11 @@ export function getInputLabels(
328328
* @param input The input that defines the end of the subset.
329329
* @returns A list of field/input labels for the given block.
330330
*/
331-
export function getInputLabelsSubset(block: BlockSvg, input: Input): string[] {
331+
export function getInputLabelsSubset(
332+
block: BlockSvg,
333+
input: Input,
334+
includeFallbackLabels = true,
335+
): string[] {
332336
const inputIndex = block.inputList.indexOf(input);
333337
if (inputIndex === -1) {
334338
throw new Error(
@@ -347,11 +351,14 @@ export function getInputLabelsSubset(block: BlockSvg, input: Input): string[] {
347351
.map(
348352
(input) =>
349353
input.getLabel(Verbosity.TERSE, false) ||
350-
Msg['INPUT_LABEL_INDEX'].replace(
351-
'%1',
352-
(input.getIndex() + 1).toString(),
353-
),
354-
);
354+
(includeFallbackLabels
355+
? Msg['INPUT_LABEL_INDEX'].replace(
356+
'%1',
357+
(input.getIndex() + 1).toString(),
358+
)
359+
: undefined),
360+
)
361+
.filter((label) => label !== undefined);
355362
}
356363

357364
/**

packages/blockly/core/rendered_connection.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,14 @@ export class RenderedConnection
355355

356356
// Use the custom label for an input if it exists, otherwise use the
357357
// "field row" approach to get the default label for the input.
358+
// Don't include the "input 1" fallback for default labels, since
359+
// the input is already being described as a statement or value input.
358360
const parentInputLabel =
359361
parentInput?.getAriaLabelText() ??
360362
getInputLabelsSubset(
361363
parentInput.getSourceBlock() as BlockSvg,
362364
parentInput,
365+
false,
363366
).join(', ');
364367
if (this.type === ConnectionType.NEXT_STATEMENT) {
365368
aria.setState(

packages/blockly/tests/mocha/aria_test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,21 @@ suite('ARIA', function () {
626626
);
627627
});
628628

629+
test('statement input connection label does not include the placeholder "input"', function () {
630+
const block = this.renderBlock('controls_repeat_ext');
631+
const doInput = block.getInput('DO');
632+
doInput.connection.highlight();
633+
try {
634+
const label = Blockly.utils.aria.getState(
635+
doInput.connection.getFocusableElement(),
636+
Blockly.utils.aria.State.LABEL,
637+
);
638+
assert.notInclude(label, 'input');
639+
} finally {
640+
doInput.connection.unhighlight();
641+
}
642+
});
643+
629644
test('last next connection in a populated statement stack uses statement role description and end label', function () {
630645
const repeat = this.renderBlock('controls_repeat_ext');
631646
const printBlock = this.renderBlock('text_print');

0 commit comments

Comments
 (0)