diff --git a/packages/blockly/core/field.ts b/packages/blockly/core/field.ts index 9b967baa135..b254e6704a6 100644 --- a/packages/blockly/core/field.ts +++ b/packages/blockly/core/field.ts @@ -318,6 +318,18 @@ export abstract class Field return this.ariaTypeName || null; } + /** + * Sets the ARIA-friendly label representation of this field's type. + * + * Implementations are responsible for, and encouraged to, set a localized + * version of the ARIA representation of the field's type. + * + * @param ariaTypeName An ARIA representation of the field's type. + */ + setAriaTypeName(ariaTypeName: string) { + this.ariaTypeName = ariaTypeName; + } + /** * Gets an ARIA-friendly label representation of this field's value. * diff --git a/packages/blockly/tests/mocha/field_test.js b/packages/blockly/tests/mocha/field_test.js index 373f44133ea..e01369a2462 100644 --- a/packages/blockly/tests/mocha/field_test.js +++ b/packages/blockly/tests/mocha/field_test.js @@ -896,6 +896,13 @@ suite('Abstract Fields', function () { assert.equal(field.computeAriaLabel(true), 'text: hello'); }); + test('Custom type and value when ariaTypeName is set', function () { + const field = new TestField(); + field.setAriaTypeName('speed'); + field.setValue('fast'); + assert.equal(field.computeAriaLabel(), 'speed: fast'); + }); + test('Type and placeholder when value is null', function () { const field = new TestField(null, {ariaTypeName: 'text'}); assert.equal(