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
7 changes: 5 additions & 2 deletions packages/blockly/core/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,15 +476,18 @@ export abstract class Field<T = any>
}

/**
* Create a field text element. Not to be overridden by subclasses. Instead
* Create a field text element. Not to be overridden by subclasses. Instead,
* modify the result of the function inside initView, or create a separate
* function to call.
* function to call. Aria state is hidden; use the aria label for the field
* and/or containing block to expose content to screen readers. Text content
* for custom blocks can be set after creation.
*/
protected createTextElement_() {
this.textElement_ = dom.createSvgElement(
Svg.TEXT,
{
'class': 'blocklyText blocklyFieldText',
'aria-hidden': 'true',
},
this.fieldGroup_,
);
Expand Down
9 changes: 9 additions & 0 deletions packages/blockly/tests/mocha/field_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -944,5 +944,14 @@ suite('Abstract Fields', function () {
assert.equal(field.computeAriaLabel(true), 'custom type: custom value');
});
});

suite('Field text elements are hidden', function () {
test('Field text element has aria-hidden=true', function () {
const field = new TestField();
field.constants_ = {FIELD_BORDER_RECT_RADIUS: 5};
field.initView();
assert(field.getTextElement().ariaHidden === 'true');
});
});
});
});
Loading