diff --git a/libs/react-components/src/lib/app-header/app-header.spec.tsx b/libs/react-components/src/lib/app-header/app-header.spec.tsx index 4433fcd72..6f451a79e 100644 --- a/libs/react-components/src/lib/app-header/app-header.spec.tsx +++ b/libs/react-components/src/lib/app-header/app-header.spec.tsx @@ -10,4 +10,15 @@ describe("GoAAppHeader", () => { const header = baseElement.querySelector("goa-app-header"); expect(header).toBeTruthy(); }); + it("should dispatch onMobileMenuClick if provided", () => { + const onMobileMenuClick = vi.fn(); + const { baseElement } = render( + + ); + + const header = baseElement.querySelector("goa-app-header"); + expect(header).toBeTruthy(); + header?.dispatchEvent(new Event("_menuClick")); + expect(onMobileMenuClick).toHaveBeenCalled(); + }) }); diff --git a/libs/react-components/src/lib/app-header/app-header.tsx b/libs/react-components/src/lib/app-header/app-header.tsx index c6a5f13d2..05d3ef889 100644 --- a/libs/react-components/src/lib/app-header/app-header.tsx +++ b/libs/react-components/src/lib/app-header/app-header.tsx @@ -1,8 +1,12 @@ +import { useEffect, useRef } from "react"; + interface WCProps { heading?: string; url?: string; maxcontentwidth?: string; fullmenubreakpoint?: number; + hasmenuclickhandler?: boolean; + ref: React.RefObject; testid?: string; } @@ -21,6 +25,7 @@ export interface GoAAppHeaderProps { maxContentWidth?: string; fullMenuBreakpoint?: number; children?: React.ReactNode; + onMenuClick?: () => void; testId?: string; } @@ -31,14 +36,36 @@ export function GoAAppHeader({ fullMenuBreakpoint, testId, children, + onMenuClick, }: GoAAppHeaderProps): JSX.Element { + const el = useRef(null); + + useEffect(() => { + if (!el.current) { + return; + } + if (!onMenuClick) { + return; + } + const current = el.current; + const listener = () => { + onMenuClick(); + } + current.addEventListener("_menuClick", listener); + return () => { + current.removeEventListener("_menuClick", listener); + } + }, [el, onMenuClick]); + return ( {children} diff --git a/libs/react-components/src/lib/side-menu-group/side-menu-group.spec.tsx b/libs/react-components/src/lib/side-menu-group/side-menu-group.spec.tsx index 5ab343d07..7e6344564 100644 --- a/libs/react-components/src/lib/side-menu-group/side-menu-group.spec.tsx +++ b/libs/react-components/src/lib/side-menu-group/side-menu-group.spec.tsx @@ -10,4 +10,12 @@ describe("SideMenuGroup", () => { expect(el?.getAttribute("heading")).toBe("some header"); expect(el?.getAttribute("testid")).toBe("foo"); }); + it("should render icon if provided", () => { + const { baseElement } = render( + , + ); + + const el = baseElement.querySelector("goa-side-menu-group"); + expect(el?.getAttribute("icon")).toBe("accessibility"); + }) }); diff --git a/libs/react-components/src/lib/three-column-layout/three-column-layout.spec.tsx b/libs/react-components/src/lib/three-column-layout/three-column-layout.spec.tsx index 54e33dda7..ba23804d5 100644 --- a/libs/react-components/src/lib/three-column-layout/three-column-layout.spec.tsx +++ b/libs/react-components/src/lib/three-column-layout/three-column-layout.spec.tsx @@ -39,7 +39,7 @@ describe("ThreeColumnLayout", () => { expect(baseElement.innerHTML).toContain( "Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat." ); - expect(baseElement.innerHTML).toContain(""); + expect(baseElement.querySelector("goa-app-header")).toBeTruthy(); expect(baseElement.innerHTML).toContain(""); expect(baseElement.querySelectorAll("[slot=nav] a").length).toEqual(5); diff --git a/libs/react-components/src/lib/two-column-layout/two-column-layout.spec.tsx b/libs/react-components/src/lib/two-column-layout/two-column-layout.spec.tsx index 343fb7663..20a3bb803 100644 --- a/libs/react-components/src/lib/two-column-layout/two-column-layout.spec.tsx +++ b/libs/react-components/src/lib/two-column-layout/two-column-layout.spec.tsx @@ -34,7 +34,7 @@ describe("TwoColumnLayout", () => { expect(baseElement.innerHTML).toContain( "Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat." ); - expect(baseElement.innerHTML).toContain(""); + expect(baseElement.querySelector("goa-app-header")).toBeTruthy(); expect(baseElement.innerHTML).toContain(""); expect(baseElement.querySelectorAll("[slot=nav] a").length).toEqual(5); }); diff --git a/libs/web-components/src/components/app-header/AppHeader.svelte b/libs/web-components/src/components/app-header/AppHeader.svelte index e9a7186a2..8ea1bb6d2 100644 --- a/libs/web-components/src/components/app-header/AppHeader.svelte +++ b/libs/web-components/src/components/app-header/AppHeader.svelte @@ -5,7 +5,7 @@