1- import { useState } from 'react'
1+ import { useState , useId } from 'react'
22import { cx } from 'class-variance-authority'
33import { SVGTooltip } from '../../../assets/svg'
44
@@ -9,16 +9,32 @@ export interface TooltipProps {
99
1010export function Tooltip ( { children, className } : TooltipProps ) {
1111 const [ open , setOpen ] = useState ( false )
12+ const tooltipId = useId ( )
13+
1214 return (
13- < div
14- className = { cx ( 'w-fit relative inline-flex' , className ) }
15- onMouseEnter = { ( ) => setOpen ( true ) }
16- onMouseLeave = { ( ) => setOpen ( false ) }
17- >
18- < SVGTooltip className = "w-6 h-6" />
15+ < div className = { cx ( 'w-fit relative inline-flex' , className ) } >
16+ < button
17+ type = "button"
18+ aria-label = "More information"
19+ aria-describedby = { open ? tooltipId : undefined }
20+ aria-expanded = { open }
21+ onMouseEnter = { ( ) => setOpen ( true ) }
22+ onMouseLeave = { ( ) => setOpen ( false ) }
23+ onFocus = { ( ) => setOpen ( true ) }
24+ onBlur = { ( ) => setOpen ( false ) }
25+ onClick = { ( ) => setOpen ( ! open ) }
26+ className = "rounded-full hover:bg-gray-100 focus:outline-none focus:ring-1 focus:ring-primary-focus"
27+ >
28+ < SVGTooltip className = "w-6 h-6" />
29+ </ button >
30+
1931 { open && (
20- < div className = "absolute z-50 left-8 top-1/2 -translate-y-1/2 w-[485px] flex items-center justify-center gap-2.5 p-4 bg-interface-tooltip rounded-lg shadow-lg" >
21- < p className = "flex-1 mt-[-1.00px] text-white" > { children } </ p >
32+ < div
33+ id = { tooltipId }
34+ role = "tooltip"
35+ className = "absolute z-50 left-8 top-1/2 -translate-y-1/2 w-[485px] flex items-center justify-center gap-2.5 p-4 bg-interface-tooltip rounded-lg shadow-lg"
36+ >
37+ < p className = "text-white text-sm leading-relaxed" > { children } </ p >
2238 </ div >
2339 ) }
2440 </ div >
0 commit comments