1- import { type JSX } from "react" ;
1+ import { useEffect , useRef , type JSX } from "react" ;
22import { GoabWorkSideMenuItemType } from "@abgov/ui-components-common" ;
33interface WCProps {
44 label : string ;
5- url : string ;
5+ url ? : string ;
66 badge ?: string ;
77 current ?: string ;
88 divider ?: string ;
@@ -15,36 +15,68 @@ declare module "react" {
1515 // eslint-disable-next-line @typescript-eslint/no-namespace
1616 namespace JSX {
1717 interface IntrinsicElements {
18- "goa-work-side-menu-item" : WCProps & React . HTMLAttributes < HTMLElement > ;
18+ "goa-work-side-menu-item" : WCProps &
19+ React . HTMLAttributes < HTMLElement > & {
20+ ref : React . RefObject < HTMLElement | null > ;
21+ } ;
1922 }
2023 }
2124}
2225
2326export interface GoabWorkSideMenuItemProps {
2427 label : string ;
25- url : string ;
28+ url ? : string ;
2629 badge ?: string ;
2730 current ?: boolean ;
2831 divider ?: boolean ;
2932 icon ?: string ;
3033 testId ?: string ;
3134 type ?: GoabWorkSideMenuItemType ;
3235 children ?: React . ReactNode ;
36+ onCLick ?: ( ) => void ;
3337}
3438
35- export function GoabxWorkSideMenuItem ( props : GoabWorkSideMenuItemProps ) : JSX . Element {
39+ export function GoabxWorkSideMenuItem ( {
40+ label,
41+ url,
42+ badge,
43+ current,
44+ divider,
45+ icon,
46+ testId,
47+ type,
48+ children,
49+ onClick,
50+ } : GoabWorkSideMenuItemProps ) : JSX . Element {
51+ const el = useRef < HTMLElement > ( null ) ;
52+
53+ useEffect ( ( ) => {
54+ if ( ! el . current ) return ;
55+ if ( ! onClick ) return ;
56+ const current = el . current ;
57+ const listener = ( ) => {
58+ onClick ?.( ) ;
59+ } ;
60+
61+ current . addEventListener ( "_click" , listener ) ;
62+ return ( ) => {
63+ current . removeEventListener ( "_click" , listener ) ;
64+ } ;
65+ } , [ el , onClick ] ) ;
66+
3667 return (
3768 < goa-work-side-menu-item
38- label = { props . label }
39- url = { props . url }
40- badge = { props . badge }
41- current = { props . current ? "true" : undefined }
42- divider = { props . divider ? "true" : undefined }
43- icon = { props . icon }
44- testid = { props . testId }
45- type = { props . type }
69+ ref = { el }
70+ label = { label }
71+ url = { url }
72+ badge = { badge }
73+ current = { current ? "true" : undefined }
74+ divider = { divider ? "true" : undefined }
75+ icon = { icon }
76+ testid = { testId }
77+ type = { type }
4678 >
47- { props . children }
79+ { children }
4880 </ goa-work-side-menu-item >
4981 ) ;
5082}
0 commit comments