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

fix: date picker a11y bug #16219

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
18 changes: 2 additions & 16 deletions e2e/components/DatePicker/DatePicker-test.avt.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ test.describe('@avt DatePicker', () => {
},
});

// for some reason the firs tab is not working to focus the first tabstop, so focusing manually
// for some reason the first tab is not working to focus the first tabstop, so focusing manually
await page.getByRole('textbox', { name: 'Date Picker label' }).focus();
await expect(
page.getByRole('textbox', { name: 'Date Picker label' })
Expand All @@ -96,9 +96,6 @@ test.describe('@avt DatePicker', () => {
await page.keyboard.press('ArrowDown');
await expect(page.locator('span.today')).toBeFocused();
await page.keyboard.press('Escape');
await expect(
page.getByRole('textbox', { name: 'Date Picker label' })
).toBeFocused();
await expect(page.locator('div.flatpickr-calendar')).not.toHaveClass(
/open/
);
Expand Down Expand Up @@ -126,18 +123,7 @@ test.describe('@avt DatePicker', () => {
await expect(page.locator('div.flatpickr-calendar')).toHaveClass(/open/);
await page.keyboard.press('ArrowDown');
await page.keyboard.press('Enter');
await expect(
page.locator('input#date-picker-input-id-start')
).toBeFocused();
await expect(page.locator('div.flatpickr-calendar')).not.toHaveClass(
/open/
);
await page.keyboard.press('Tab');
await expect(
page.locator('input#date-picker-input-id-finish')
).toBeFocused();
await expect(page.locator('div.flatpickr-calendar')).toHaveClass(/open/);
await page.keyboard.press('Escape');
await page.keyboard.press('Enter');
await expect(
page.locator('input#date-picker-input-id-finish')
).toBeFocused();
Expand Down
13 changes: 0 additions & 13 deletions e2e/components/FluidDatePicker/FluidDatePicker-test.avt.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ test.describe('@avt FluidDatePicker', () => {
await page.keyboard.press('ArrowDown');
await expect(page.locator('span.today')).toBeFocused();
await page.keyboard.press('Escape');
await expect(page.getByRole('textbox', { name: 'Label' })).toBeFocused();
await expect(page.locator('div.flatpickr-calendar')).not.toHaveClass(
/open/
);
Expand Down Expand Up @@ -98,18 +97,6 @@ test.describe('@avt FluidDatePicker', () => {
await expect(page.locator('div.flatpickr-calendar')).toHaveClass(/open/);
await page.keyboard.press('ArrowDown');
await page.keyboard.press('Enter');
await expect(
page.locator('input#date-picker-input-id-start')
).toBeFocused();
await expect(page.locator('div.flatpickr-calendar')).not.toHaveClass(
/open/
);
await page.keyboard.press('Tab');
await expect(
page.locator('input#date-picker-input-id-finish')
).toBeFocused();
await expect(page.locator('div.flatpickr-calendar')).toHaveClass(/open/);
await page.keyboard.press('Escape');
await expect(
page.locator('input#date-picker-input-id-finish')
).toBeFocused();
Expand Down
5 changes: 5 additions & 0 deletions packages/react/src/components/DatePicker/DatePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ const DatePicker = React.forwardRef(function DatePicker(

// fix datepicker deleting the selectedDate when the calendar closes
const onCalendarClose = (selectedDates, dateStr) => {
endInputField?.current?.focus();
calendarRef.current.calendarContainer.classList.remove('open');
setTimeout(() => {
if (
lastStartValue.current &&
Expand Down Expand Up @@ -671,6 +673,9 @@ const DatePicker = React.forwardRef(function DatePicker(
}

if (match(event, keys.ArrowDown)) {
if (event.target == endInputField.current) {
calendar.calendarContainer.classList.add('open');
}
const {
calendarContainer,
selectedDateElem: fpSelectedDateElem,
Expand Down