diff --git a/playwright/index.tsx b/playwright/index.tsx index c3ddeef0ce..acc0c594c2 100644 --- a/playwright/index.tsx +++ b/playwright/index.tsx @@ -25,10 +25,7 @@ const mountedTheme = (theme: string) => { // Setup required providers on mounted component before running test. See https://playwright.dev/docs/test-components#hooks beforeMount(async ({ App, hooksConfig }) => { - const { - theme = "sage", - validationRedesignOptIn, - } = hooksConfig || {}; + const { theme = "sage", validationRedesignOptIn } = hooksConfig || {}; return ( { const date = d as Date; handleDayClick(date, e); }} components={{ - Nav: (props) => { - return ; - }, + Nav, Weekday: (props) => { const fixedDays = { Sunday: 0, diff --git a/src/components/date/__internal__/date-picker/date-picker.test.tsx b/src/components/date/__internal__/date-picker/date-picker.test.tsx index 7d4d234987..498c69ad31 100644 --- a/src/components/date/__internal__/date-picker/date-picker.test.tsx +++ b/src/components/date/__internal__/date-picker/date-picker.test.tsx @@ -454,3 +454,31 @@ test("should correctly translate the month caption for the given locale (zh-CN)" expect(monthCaption).toBeVisible(); expect(monthCaption).toHaveTextContent("三月 2019"); }); + +test("navigation buttons should maintain focus between month changes when using the keyboard", async () => { + const user = userEvent.setup(); + render( + {}} + open + selectedDays={new Date(2019, 3, 4)} + />, + ); + + const textbox = screen.getByRole("textbox"); + const monthLabel = screen.getByText("April 2019"); + const previousButton = screen.getByRole("button", { name: "Previous month" }); + const nextButton = screen.getByRole("button", { name: "Next month" }); + + await user.click(textbox); + await user.tab(); + expect(previousButton).toHaveFocus(); + await user.keyboard("{enter}"); + expect(monthLabel).toHaveTextContent("March 2019"); + expect(previousButton).toHaveFocus(); + await user.tab(); + expect(nextButton).toHaveFocus(); + await user.keyboard("{enter}"); + expect(monthLabel).toHaveTextContent("April 2019"); + expect(nextButton).toHaveFocus(); +}); diff --git a/src/components/date/date.pw.tsx b/src/components/date/date.pw.tsx index cc714d9c97..1d732f3238 100644 --- a/src/components/date/date.pw.tsx +++ b/src/components/date/date.pw.tsx @@ -501,6 +501,7 @@ test.describe("Functionality tests", () => { await datePicker.press("Escape"); + await dateInput.waitFor(); await expect(dateInput).toBeFocused(); await expect(datePicker).toBeHidden(); });