Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DatePicker a11y fixes #1486

Merged
merged 13 commits into from
Aug 16, 2023
5 changes: 5 additions & 0 deletions .changeset/pink-shirts-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@itwin/itwinui-react': patch
---

DatePicker date tables now have accessible labels.
2 changes: 1 addition & 1 deletion examples/DatePicker.menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default () => {

return (
<>
<IconButton onClick={() => setOpened(!opened)} id='picker-button'>
<IconButton onClick={() => setOpened(!opened)} label='Choose date'>
<SvgCalendar />
</IconButton>
<span style={{ marginLeft: 16 }}>{currentDate.toString()}</span>
Expand Down
10 changes: 9 additions & 1 deletion packages/itwinui-react/src/core/DatePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
SvgChevronRightDouble,
isBefore,
Box,
useId,
} from '../utils/index.js';
import type { PolymorphicForwardRefComponent } from '../utils/index.js';
import { IconButton } from '../Buttons/IconButton/index.js';
Expand Down Expand Up @@ -525,6 +526,8 @@ export const DatePicker = React.forwardRef((props, forwardedRef) => {
return dayClass;
};

const dateTableId = useId();

return (
<Box
className={cx('iui-date-picker', className)}
Expand Down Expand Up @@ -555,6 +558,7 @@ export const DatePicker = React.forwardRef((props, forwardedRef) => {
<Box
as='span'
className='iui-calendar-month'
id={dateTableId}
title={monthNames[displayedMonthIndex]}
>
{monthNames[displayedMonthIndex]}
Expand Down Expand Up @@ -587,7 +591,11 @@ export const DatePicker = React.forwardRef((props, forwardedRef) => {
</div>
))}
</Box>
<div onKeyDown={handleCalendarKeyDown} role='listbox'>
<div
onKeyDown={handleCalendarKeyDown}
role='listbox'
aria-labelledby={dateTableId}
>
{weeks.map((weekDays, weekIndex) => {
return (
<Box
Expand Down