Skip to content

Commit d2d898d

Browse files
(Datepicker): improve a11y
1 parent 226d03f commit d2d898d

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/scripts/Datepicker.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,13 @@ const DatepickerFilter: FC<DatepickerFilterProps> = (props) => {
150150
onClick={onPrevMonth}
151151
/>
152152
</div>
153-
<h2 className='slds-align-middle'>{dayjs.monthsShort()[cal.month]}</h2>
153+
<h2
154+
className='slds-align-middle'
155+
aria-atomic='false'
156+
aria-live='polite'
157+
>
158+
{dayjs.monthsShort()[cal.month]}
159+
</h2>
154160
<div className='slds-align-middle'>
155161
<Button
156162
type='icon-container'
@@ -195,7 +201,6 @@ type DatepickerDateProps = {
195201
selectedDate: string | undefined;
196202
today: string;
197203
date: CalendarDate;
198-
dayIndex: number;
199204
} & DatepickerHandlers;
200205

201206
/**
@@ -207,7 +212,6 @@ const DatepickerDate: FC<DatepickerDateProps> = (props) => {
207212
selectedDate,
208213
today,
209214
date,
210-
dayIndex,
211215
onDateKeyDown: onDateKeyDown_,
212216
onDateClick: onDateClick_,
213217
onDateFocus: onDateFocus_,
@@ -250,10 +254,10 @@ const DatepickerDate: FC<DatepickerDateProps> = (props) => {
250254
return (
251255
<td
252256
className={dateClassName}
253-
headers={dayjs().weekday(dayIndex).format('ddd')}
254257
role='gridcell'
255-
aria-disabled={!enabled}
256258
aria-selected={selected}
259+
aria-current={isToday ? 'date' : undefined}
260+
aria-label={dayjs(date.value).format('D MMMM YYYY')}
257261
>
258262
<span
259263
className='slds-day'
@@ -293,7 +297,12 @@ const DatepickerMonth = forwardRef(
293297
onDateKeyDown,
294298
} = props;
295299
return (
296-
<table ref={ref} className='slds-datepicker__month' role='grid'>
300+
<table
301+
ref={ref}
302+
className='slds-datepicker__month'
303+
role='grid'
304+
aria-multiselectable='true'
305+
>
297306
<thead>
298307
<tr>
299308
{dayjs.weekdaysMin(true).map((wd, i) => (
@@ -485,7 +494,9 @@ export const Datepicker: FC<DatepickerProps> = (props) => {
485494
className={datepickerClassNames}
486495
ref={elementRef}
487496
tabIndex={-1}
497+
role='dialog'
488498
aria-hidden={false}
499+
aria-label={`Date picker: ${dayjs.monthsShort()[cal.month]}`}
489500
onBlur={onBlur}
490501
onKeyDown={onKeyDown}
491502
>

0 commit comments

Comments
 (0)