Skip to content

Commit 14bb76a

Browse files
committed
refactor(CPopover): improve accessibility
1 parent 21fe7d0 commit 14bb76a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/coreui-react/src/components/popover/CPopover.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ export const CPopover = forwardRef<HTMLDivElement, CPopoverProps>(
9999
const popoverRef = useRef(null)
100100
const togglerRef = useRef(null)
101101
const forkedRef = useForkedRef(ref, popoverRef)
102-
102+
const uID = useRef(`popover${Math.floor(Math.random() * 1_000_000)}`)
103+
103104
const { initPopper, destroyPopper } = usePopper()
104105
const [_visible, setVisible] = useState(visible)
105106

@@ -155,6 +156,9 @@ export const CPopover = forwardRef<HTMLDivElement, CPopoverProps>(
155156
return (
156157
<>
157158
{React.cloneElement(children as React.ReactElement<any>, {
159+
...(_visible && {
160+
'aria-describedby': uID.current,
161+
}),
158162
ref: togglerRef,
159163
...((trigger === 'click' || trigger.includes('click')) && {
160164
onClick: () => toggleVisible(!_visible),
@@ -194,6 +198,7 @@ export const CPopover = forwardRef<HTMLDivElement, CPopoverProps>(
194198
},
195199
className,
196200
)}
201+
id={uID.current}
197202
ref={forkedRef}
198203
role="tooltip"
199204
{...rest}

0 commit comments

Comments
 (0)