Skip to content

Commit

Permalink
fix(vertical-menu-full-screen): ensure the call to action element is …
Browse files Browse the repository at this point in the history
…focused on close
  • Loading branch information
tomdavies73 committed Dec 11, 2024
1 parent 3546edf commit f336a34
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/components/vertical-menu/components.test-pw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,11 @@ export const VerticalMenuTriggerCustom = (
);
};

export const VerticalMenuFullScreenCustom = (
props: Partial<VerticalMenuFullScreenProps>,
) => {
const [isMenuOpen, setIsMenuOpen] = useState(false);
export const VerticalMenuFullScreenCustom = ({
isOpen = false,
...props
}: Partial<VerticalMenuFullScreenProps> & { isOpen?: boolean }) => {
const [isMenuOpen, setIsMenuOpen] = useState(isOpen);

const fullscreenViewBreakPoint = useMediaQuery("(max-width: 1200px)");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const VerticalMenuFullScreen = ({
closeModal: handleKeyDown,
modalRef: menuWrapperRef,
topModalOverride: true,
focusCallToActionElement: document.activeElement as HTMLElement,
});

// TODO remove this as part of FE-5650
Expand Down
39 changes: 39 additions & 0 deletions src/components/vertical-menu/vertical-menu.pw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
checkGoldenOutline,
assertCssValueIsApproximately,
checkAccessibility,
waitForAnimationEnd,
} from "../../../playwright/support/helper";
import {
verticalMenuComponent,
Expand Down Expand Up @@ -316,6 +317,44 @@ test.describe("with beforeEach for VerticalMenuFullScreen", () => {
await expect(verticalMenuItem(page).first()).toBeVisible();
});

test("when a Vertical Menu Fullscreen is opened and then closed, the call to action element should be focused", async ({
mount,
page,
}) => {
await mount(<VerticalMenuFullScreenCustom />);

const item = page.getByRole("button").filter({ hasText: "Menu" });
await item.click();
const verticalMenuFulScreen = verticalMenuFullScreen(page);
await waitForAnimationEnd(verticalMenuFulScreen);
const closeButton = page.getByLabel("Close");
await closeButton.click();
await expect(item).toBeFocused();
});

test("when Vertical Menu Fullscreen is open on render, then closed, opened and then closed again, the call to action element should be focused", async ({
mount,
page,
}) => {
await mount(<VerticalMenuFullScreenCustom isOpen />);

const verticalMenuFulScreen = verticalMenuFullScreen(page);
await waitForAnimationEnd(verticalMenuFulScreen);
await expect(verticalMenuFulScreen).toBeVisible();
const closeButton = page.getByLabel("Close");
await closeButton.click();

const item = page.getByRole("button").filter({ hasText: "Menu" });
await expect(item).not.toBeFocused();
await expect(verticalMenuFulScreen).not.toBeVisible();

await item.click();
await waitForAnimationEnd(verticalMenuFulScreen);
await expect(verticalMenuFulScreen).toBeVisible();
await closeButton.click();
await expect(item).toBeFocused();
});

test(`should verify that Vertical Menu Fullscreen has no effect on the tab order when isOpen prop is false`, async ({
mount,
page,
Expand Down

0 comments on commit f336a34

Please sign in to comment.