Skip to content

Commit 8596a28

Browse files
committed
fix: Improve accessibility of FieldDate
1 parent 50e4b7f commit 8596a28

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

plugins/field-date/src/field_date.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,32 @@ export class FieldDate extends Blockly.FieldTextInput {
9393
return getLocaleDateString(value);
9494
}
9595

96+
/**
97+
* Returns a description of the type of this field for screenreaders.
98+
*/
99+
override getAriaTypeName() {
100+
return Blockly.Msg['ARIA_TYPE_FIELD_DATE'];
101+
}
102+
103+
/**
104+
* Returns a description of the current date for use by screenreaders.
105+
*/
106+
override getAriaValue() {
107+
const stringValue = this.getValue();
108+
if (!stringValue) return super.getAriaValue();
109+
110+
const date = new Date(stringValue);
111+
// Use a localized long-form description of the date, e.g. January XX, 20XX,
112+
// rather than a short-form/ISO version of the date which may be read out
113+
// with slashes or the like.
114+
return date.toLocaleDateString(undefined, {
115+
year: 'numeric',
116+
month: 'long',
117+
day: 'numeric',
118+
timeZone: 'UTC',
119+
});
120+
}
121+
96122
/**
97123
* Renders the field. If the picker is shown make sure it has the current
98124
* date selected.

0 commit comments

Comments
 (0)