Skip to content

Commit afb89eb

Browse files
authored
fix(datepicker): add weekday to calendar aria-labels (#22141)
* fix(react): add weekday to date picker aria-labels and added tests * fix(wc): add weekday to date picker aria-labels and added tests
1 parent cb5b293 commit afb89eb

4 files changed

Lines changed: 54 additions & 4 deletions

File tree

packages/react/src/components/DatePicker/DatePicker-test.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,28 @@ describe('Single date picker', () => {
653653
expect(screen.getByRole('application')).toBeInTheDocument();
654654
});
655655

656+
it('should include the weekday in the calendar day aria-label', async () => {
657+
render(
658+
<DatePicker
659+
onChange={() => {}}
660+
datePickerType="single"
661+
value="04/15/2026">
662+
<DatePickerInput
663+
id="date-picker-input-id-start"
664+
placeholder="mm/dd/yyyy"
665+
labelText="Start date"
666+
data-testid="input"
667+
/>
668+
</DatePicker>
669+
);
670+
671+
await userEvent.click(screen.getByTestId('input'));
672+
673+
expect(
674+
screen.getByLabelText('Wednesday, April 15, 2026')
675+
).toBeInTheDocument();
676+
});
677+
656678
it('should update the calendar classnames when open', async () => {
657679
render(
658680
<DatePicker
@@ -806,7 +828,7 @@ describe('Single date picker', () => {
806828

807829
// eslint-disable-next-line testing-library/no-node-access
808830
const belowMinDate = document.querySelector(
809-
'[aria-label="November 26, 2023"]'
831+
'[aria-label="Sunday, November 26, 2023"]'
810832
);
811833
await userEvent.click(belowMinDate);
812834

@@ -1689,7 +1711,7 @@ describe('Date picker with minDate and maxDate', () => {
16891711
await userEvent.click(screen.getByTestId('input'));
16901712

16911713
const disabledDate = document.querySelector(
1692-
'[aria-label="January 2, 2018"]'
1714+
'[aria-label="Tuesday, January 2, 2018"]'
16931715
);
16941716

16951717
expect(disabledDate).toHaveClass('flatpickr-disabled');
@@ -1744,7 +1766,7 @@ describe('Date picker with minDate and maxDate', () => {
17441766
);
17451767
// eslint-disable-next-line testing-library/no-node-access
17461768
const belowMinDate = document.querySelector(
1747-
'[aria-label="December 31, 2017"]'
1769+
'[aria-label="Sunday, December 31, 2017"]'
17481770
);
17491771
await userEvent.click(screen.getByTestId('input-min-max'));
17501772
await userEvent.click(belowMinDate);
@@ -1772,7 +1794,7 @@ describe('Date picker with minDate and maxDate', () => {
17721794

17731795
// eslint-disable-next-line testing-library/no-node-access
17741796
const aboveMaxDate = document.querySelector(
1775-
'[aria-label="January 4, 2018"]'
1797+
'[aria-label="Thursday, January 4, 2018"]'
17761798
);
17771799

17781800
await userEvent.click(screen.getByTestId('input-min-max-2'));

packages/react/src/components/DatePicker/DatePicker.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function initializeWeekdayShorthand() {
5454
}
5555

5656
const forEach = Array.prototype.forEach;
57+
const defaultAriaDateFormat = 'l, F j, Y';
5758

5859
/**
5960
* @param {number} monthNumber The month number.
@@ -603,6 +604,7 @@ const DatePicker = forwardRef<HTMLDivElement, DatePickerProps>((props, ref) => {
603604
inline: inline ?? false,
604605
onClose: onCalendarClose,
605606
disableMobile: true,
607+
ariaDateFormat: defaultAriaDateFormat,
606608
defaultDate: value,
607609
closeOnSelect: closeOnSelect,
608610
mode: datePickerType,

packages/web-components/src/components/date-picker/__tests__/date-picker-test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,25 @@ describe('cds-date-picker', () => {
126126
expect(el).to.exist;
127127
});
128128

129+
it('should include the weekday in the calendar day aria-label', async () => {
130+
const el = await fixture(html`
131+
<cds-date-picker value="2026-04-15">
132+
<cds-date-picker-input
133+
kind="single"
134+
label-text="Date"
135+
placeholder="mm/dd/yyyy">
136+
</cds-date-picker-input>
137+
</cds-date-picker>
138+
`);
139+
await el.updateComplete;
140+
141+
const day = el.calendar?.calendarContainer?.querySelector(
142+
'[aria-label="Wednesday, April 15, 2026"]'
143+
);
144+
145+
expect(day).to.exist;
146+
});
147+
129148
it('should handle value changes', async () => {
130149
const el = await fixture(html`
131150
<cds-date-picker value="2024-01-15">

packages/web-components/src/components/date-picker/date-picker.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ class CDSDatePicker extends HostListenerMixin(FormMixin(LitElement)) {
202202
: enabledRange.split('/');
203203
return {
204204
allowInput: this.allowInput,
205+
ariaDateFormat: (this.constructor as typeof CDSDatePicker)
206+
.defaultAriaDateFormat,
205207
closeOnSelect: this.closeOnSelect,
206208
dateFormat:
207209
this.dateFormat ??
@@ -663,6 +665,11 @@ class CDSDatePicker extends HostListenerMixin(FormMixin(LitElement)) {
663665
*/
664666
static classNoBorder = 'no-border';
665667

668+
/**
669+
* The default aria date format.
670+
*/
671+
static defaultAriaDateFormat = 'l, F j, Y';
672+
666673
/**
667674
* The default date format.
668675
*/

0 commit comments

Comments
 (0)