Skip to content
Open
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
12 changes: 12 additions & 0 deletions packages/blockly/core/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,18 @@ export abstract class Field<T = any>
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.
*
Expand Down
7 changes: 7 additions & 0 deletions packages/blockly/tests/mocha/field_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading