Skip to content

Commit 988b297

Browse files
Tooltip2: hide the tooltip from AT when it is not open (#3910)
* Tooltip2: hide the tooltip from AT when it is not open * Revert back the downgrade of polyfill version and remove css polyfill * fix flashing * changeset
1 parent 5750787 commit 988b297

File tree

2 files changed

+35
-46
lines changed

2 files changed

+35
-46
lines changed

.changeset/selfish-drinks-burn.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+
Tooltip (draft): Do not expose the tooltip text to AT when it is not visible

src/drafts/Tooltip/Tooltip.tsx

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,6 @@ import {getAnchoredPosition} from '@primer/behaviors'
1111
import type {AnchorSide, AnchorAlignment} from '@primer/behaviors'
1212
import {isSupported, apply} from '@oddbird/popover-polyfill/fn'
1313

14-
// Reusable styles to use for :popover-open (Chrome, Edge) and \:popover-open (Safari, Firefox) classes
15-
const popoverStyles = `
16-
padding: 0.5em 0.75em;
17-
width: max-content;
18-
height: fit-content;
19-
margin: auto;
20-
clip: auto;
21-
white-space: normal;
22-
/* for scrollbar */
23-
overflow: visible;
24-
`
25-
2614
const animationStyles = `
2715
animation-name: tooltip-appear;
2816
animation-duration: 0.1s;
@@ -32,43 +20,39 @@ const animationStyles = `
3220
`
3321

3422
const StyledTooltip = styled.div`
35-
/* tooltip element should be rendered visually hidden when it is not opened. */
36-
width: 1px;
37-
height: 1px;
38-
padding: 0;
39-
margin: -1px;
40-
overflow: hidden;
41-
clip: rect(0, 0, 0, 0);
42-
white-space: nowrap;
43-
position: fixed;
44-
font: normal normal 11px/1.5 ${get('fonts.normal')};
45-
-webkit-font-smoothing: subpixel-antialiased;
46-
color: ${get('colors.fg.onEmphasis')};
47-
text-align: center;
48-
49-
word-wrap: break-word;
50-
background: ${get('colors.neutral.emphasisPlus')}; //bg--emphasis-color
51-
border-radius: ${get('radii.2')};
52-
border: 0;
53-
opacity: 0;
54-
max-width: 250px;
55-
inset: auto;
56-
57-
@media (forced-colors: active) {
58-
outline: 1px solid transparent;
23+
/* Overriding the default popover styles */
24+
display: none;
25+
&[popover] {
26+
padding: 0.5em 0.75em;
27+
width: max-content;
28+
margin: auto;
29+
clip: auto;
30+
white-space: normal;
31+
font: normal normal 11px/1.5 ${get('fonts.normal')};
32+
-webkit-font-smoothing: subpixel-antialiased;
33+
color: ${get('colors.fg.onEmphasis')};
34+
text-align: center;
35+
word-wrap: break-word;
36+
background: ${get('colors.neutral.emphasisPlus')};
37+
border-radius: ${get('radii.2')};
38+
border: 0;
39+
opacity: 0;
40+
max-width: 250px;
41+
inset: auto;
42+
/* for scrollbar */
43+
overflow: visible;
5944
}
60-
/* pollyfil */
61-
z-index: 2147483647;
62-
display: block;
63-
6445
/* class name in chrome is :popover-open */
65-
&:popover-open {
66-
${popoverStyles}
46+
&[popover]:popover-open {
47+
display: block;
6748
}
68-
6949
/* class name in firefox and safari is \:popover-open */
70-
&.\\:popover-open {
71-
${popoverStyles}
50+
&[popover].\\:popover-open {
51+
display: block;
52+
}
53+
54+
@media (forced-colors: active) {
55+
outline: 1px solid transparent;
7256
}
7357
7458
// This is needed to keep the tooltip open when the user leaves the trigger element to hover tooltip
@@ -284,7 +268,7 @@ export const Tooltip = React.forwardRef(
284268

285269
return (
286270
<TooltipContext.Provider value={{tooltipId}}>
287-
<Box sx={{display: 'inline-block'}} onMouseLeave={() => closeTooltip()}>
271+
<Box onMouseLeave={() => closeTooltip()}>
288272
{React.isValidElement(child) &&
289273
React.cloneElement(child as React.ReactElement<TriggerPropsType>, {
290274
ref: triggerRef,

0 commit comments

Comments
 (0)