Skip to content

Commit 752bea4

Browse files
Tooltip: Do not wrap the tooltip and the trigger in a div (#4056)
* Do not wrap the tooltip and the trigger in a div * add cahngeset * align inactive item to the start after updating tooltip container
1 parent 8a8973c commit 752bea4

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

.changeset/empty-starfishes-relate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': patch
3+
---
4+
5+
Tooltip2: Do not wrap the tooltip span and its trigger in a div

src/ActionList/Item.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const InactiveIndicator: React.FC<{
3434
padding: 0,
3535
font: 'inherit',
3636
cursor: 'pointer',
37+
display: 'flex',
3738
}}
3839
aria-labelledby={labelId}
3940
>

src/drafts/Tooltip/Tooltip.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, {Children, useEffect, useRef, useState} from 'react'
2-
import Box from '../../Box'
32
import sx, {SxProp} from '../../sx'
43
import {useId, useProvidedRefOrCreate} from '../../hooks'
54
import {invariant} from '../../utils/invariant'
@@ -139,6 +138,7 @@ export type TriggerPropsType = {
139138
onBlur?: React.FocusEventHandler
140139
onFocus?: React.FocusEventHandler
141140
onMouseEnter?: React.MouseEventHandler
141+
onMouseLeave?: React.MouseEventHandler
142142
ref?: React.RefObject<HTMLElement>
143143
}
144144

@@ -268,7 +268,7 @@ export const Tooltip = React.forwardRef(
268268

269269
return (
270270
<TooltipContext.Provider value={{tooltipId}}>
271-
<Box onMouseLeave={() => closeTooltip()}>
271+
<>
272272
{React.isValidElement(child) &&
273273
React.cloneElement(child as React.ReactElement<TriggerPropsType>, {
274274
ref: triggerRef,
@@ -288,6 +288,10 @@ export const Tooltip = React.forwardRef(
288288
openTooltip()
289289
child.props.onMouseEnter?.(event)
290290
},
291+
onMouseLeave: (event: React.MouseEvent) => {
292+
closeTooltip()
293+
child.props.onMouseLeave?.(event)
294+
},
291295
})}
292296
<StyledTooltip
293297
ref={tooltipElRef}
@@ -298,10 +302,13 @@ export const Tooltip = React.forwardRef(
298302
// stop AT from announcing the tooltip twice when it is a label type because it will be announced with "aria-labelledby"
299303
aria-hidden={type === 'label' ? true : undefined}
300304
id={`tooltip-${tooltipId}`}
305+
// mouse leave and enter on the tooltip itself is needed to keep the tooltip open when the mouse is over the tooltip
306+
onMouseEnter={openTooltip}
307+
onMouseLeave={closeTooltip}
301308
>
302309
{text}
303310
</StyledTooltip>
304-
</Box>
311+
</>
305312
</TooltipContext.Provider>
306313
)
307314
},

0 commit comments

Comments
 (0)