Skip to content

Commit 716b042

Browse files
authored
Move tooltips to a dedicated container element (#10731)
This should fix the z-index issues we've been seeing since the last reimplementation of the tooltips.
1 parent cb04e06 commit 716b042

File tree

9 files changed

+89
-77
lines changed

9 files changed

+89
-77
lines changed

app/components/dependency-list/row.module.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@
3737
cursor: help;
3838
}
3939

40-
.tooltip {
41-
word-break: break-all;
42-
}
43-
4440
@media only screen and (max-width: 550px) {
4541
display: block
4642
}
4743
}
4844

45+
.tooltip {
46+
word-break: break-all;
47+
}
48+
4949
.range-lg, .range-sm {
5050
margin-right: var(--space-s);
5151
min-width: 100px;

app/components/tooltip.hbs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
<div ...attributes local-class="tooltip" {{attach-tooltip hide=this.hide show=this.show side=@side}}>
2-
{{#unless this.hidden}}
3-
{{#if (has-block)}}
4-
{{yield}}
5-
{{else}}
6-
{{@text}}
7-
{{/if}}
8-
{{/unless}}
9-
</div>
1+
<span local-class="anchor" {{this.onInsertAnchor this}} />
2+
3+
{{#if this.visible}}
4+
{{#in-element this.containerElement}}
5+
<div ...attributes local-class="tooltip" {{this.attachTooltip this side=@side}}>
6+
{{#if (has-block)}}
7+
{{yield}}
8+
{{else}}
9+
{{@text}}
10+
{{/if}}
11+
</div>
12+
{{/in-element}}
13+
{{/if}}

app/components/tooltip.js

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,65 @@ import { action } from '@ember/object';
22
import Component from '@glimmer/component';
33
import { tracked } from '@glimmer/tracking';
44

5+
import { autoUpdate, computePosition, flip, offset, shift } from '@floating-ui/dom';
6+
import { modifier } from 'ember-modifier';
7+
58
export default class Tooltip extends Component {
6-
@tracked hidden = true;
9+
@tracked anchorElement = null;
10+
@tracked visible = false;
711

8-
@action hide() {
9-
this.hidden = true;
12+
get containerElement() {
13+
return document.querySelector('#tooltip-container');
1014
}
1115

1216
@action show() {
13-
this.hidden = false;
17+
this.visible = true;
18+
}
19+
20+
@action hide() {
21+
this.visible = false;
1422
}
23+
24+
onInsertAnchor = modifier((anchor, [component]) => {
25+
component.anchorElement = anchor.parentElement;
26+
27+
let events = [
28+
['mouseenter', component.show],
29+
['mouseleave', component.hide],
30+
['focus', component.show],
31+
['blur', component.hide],
32+
];
33+
34+
for (let [event, listener] of events) {
35+
component.anchorElement.addEventListener(event, listener);
36+
}
37+
38+
return () => {
39+
for (let [event, listener] of events) {
40+
component.anchorElement?.removeEventListener(event, listener);
41+
}
42+
};
43+
});
44+
45+
attachTooltip = modifier((floatingElement, [component], { side = 'top' } = {}) => {
46+
let referenceElement = component.anchorElement;
47+
48+
async function update() {
49+
let middleware = [offset(5), flip(), shift({ padding: 5 })];
50+
51+
let { x, y } = await computePosition(referenceElement, floatingElement, {
52+
placement: side,
53+
middleware,
54+
});
55+
56+
Object.assign(floatingElement.style, {
57+
left: `${x}px`,
58+
top: `${y}px`,
59+
});
60+
}
61+
62+
let cleanup = autoUpdate(referenceElement, floatingElement, update);
63+
64+
return () => cleanup();
65+
});
1566
}

app/components/tooltip.module.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.tooltip {
2-
display: none;
32
width: max-content;
43
max-width: 300px;
54
position: absolute;
@@ -20,3 +19,7 @@
2019
color: unset;
2120
}
2221
}
22+
23+
.anchor {
24+
display: none;
25+
}

app/components/version-list/row.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
{{@version.releaseTrack}}
1919
{{/if}}
2020

21-
<Tooltip @side="right" local-class="tooltip" data-test-release-track-title>
21+
<Tooltip @side="right" local-class="rt-tooltip" data-test-release-track-title>
2222
{{this.releaseTrackTitle}}
2323
</Tooltip>
2424
</div>

app/components/version-list/row.module.css

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@
5656
grid-template-columns: auto auto;
5757
place-items: center;
5858

59-
.tooltip {
60-
word-break: break-all;
61-
}
62-
6359
@media only screen and (max-width: 550px) {
6460
grid-template-columns: auto;
6561
margin: 0 var(--space-s);
@@ -109,6 +105,10 @@
109105
color: hsl(0, 87%, 58%);
110106
}
111107

108+
.rt-tooltip {
109+
word-break: break-all;
110+
}
111+
112112
.num-link {
113113
max-width: 200px;
114114
text-overflow: ellipsis;
@@ -161,11 +161,6 @@
161161
margin-bottom: -.1em;
162162
}
163163

164-
.tooltip {
165-
text-transform: none;
166-
letter-spacing: normal;
167-
}
168-
169164
> * + * {
170165
margin-top: var(--space-2xs);
171166

@@ -226,6 +221,13 @@
226221
padding: 0;
227222
margin: var(--space-2xs) var(--space-3xs);
228223
list-style: none;
224+
225+
svg {
226+
height: 1em;
227+
width: auto;
228+
margin-right: var(--space-4xs);
229+
margin-bottom: -.1em;
230+
}
229231
}
230232

231233
.yank-button {

app/modifiers/attach-tooltip.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

app/styles/shared/typography.module.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
strong {
66
color: var(--main-color);
77
}
8-
9-
:global(.tooltip) strong {
10-
color: inherit;
11-
}
128
}
139

1410
.small a, a.small {

app/templates/application.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
<ProgressBar/>
77
<NotificationContainer @position="top-right"/>
8+
<div id="tooltip-container"></div>
89

910
<Header @hero={{this.isIndex}} />
1011

0 commit comments

Comments
 (0)