fix: Field text hidden from ARIA (#9734)

This commit is contained in:
lizschwab
2026-04-17 15:18:23 -07:00
committed by GitHub
parent 1de9aa920e
commit 2903ec9f3a
2 changed files with 14 additions and 2 deletions
+5 -2
View File
@@ -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_,
);
@@ -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');
});
});
});
});