Skip to content

Commit 02ede7d

Browse files
committed
Easier to read
1 parent fa79888 commit 02ede7d

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

packages/react/src/TooltipV2/Tooltip.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,21 @@ export const Tooltip = React.forwardRef(
247247
React.cloneElement(child as React.ReactElement<TriggerPropsType>, {
248248
ref: triggerRef,
249249
// If it is a type description, we use tooltip to describe the trigger
250-
'aria-describedby':
251-
type === 'description'
252-
? child.props['aria-describedby']
253-
? `${child.props['aria-describedby']} ${tooltipId}`
254-
: tooltipId
255-
: child.props['aria-describedby'],
250+
'aria-describedby': (() => {
251+
// If tooltip is not a description type, keep the original aria-describedby
252+
if (type !== 'description') {
253+
return child.props['aria-describedby']
254+
}
255+
256+
// If tooltip is a description type, append our tooltipId
257+
const existingDescribedBy = child.props['aria-describedby']
258+
if (existingDescribedBy) {
259+
return `${existingDescribedBy} ${tooltipId}`
260+
}
261+
262+
// If no existing aria-describedby, use our tooltipId
263+
return tooltipId
264+
})(),
256265
// If it is a label type, we use tooltip to label the trigger
257266
'aria-labelledby': type === 'label' ? tooltipId : child.props['aria-labelledby'],
258267
onBlur: (event: React.FocusEvent) => {

0 commit comments

Comments
 (0)