Skip to content

Commit 00f6644

Browse files
authored
Merge pull request #404 from primer/brocs/tooltips_fix
[WIP Tooltip component updates
2 parents 7872868 + f7b1ec7 commit 00f6644

File tree

4 files changed

+184
-32
lines changed

4 files changed

+184
-32
lines changed

modules/primer-support/lib/variables/misc.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $box-shadow-extra-large: 0 10px 50px rgba($black, 0.07) !default;
1919

2020
// Tooltips
2121
$tooltip-max-width: 250px !default;
22-
$tooltip-background-color: rgba($black, 0.8) !default;
22+
$tooltip-background-color: $black;
2323
$tooltip-text-color: $white !default;
2424
$tooltip-delay: 0.4s !default;
2525
$tooltip-duration: 0.1s !default;

modules/primer-tooltips/README.md

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,18 @@ title: Tooltips
4040
status: Stable
4141
-->
4242

43-
Add tooltips built entirely in CSS to nearly any element. Just add a few classes and an `aria-label` attribute.
43+
Add tooltips built entirely in CSS to nearly any element.
44+
45+
{:toc}
46+
47+
## Implementation and accessibility
4448

4549
**Attention**: we use `aria-label` for tooltips instead of something like `data-tooltip` because it is crucial that the tooltip content is available for screen reader users as well. However, `aria-label` **replaces** the text content of an element for screen reader users, so only use tooltip if there is no better way to present the information, or consider using `title` for supplement information.
4650

47-
In addition, you'll want to specify a direction:
51+
**Note:** Tooltip classes will conflict with Octicon styles, and as such, must be applied to the parent element instead of the icon.
52+
53+
## Tooltip direction
54+
Specify the direction of a tooltip with north, south, east, and west directions:
4855

4956
- `.tooltipped-n`
5057
- `.tooltipped-ne`
@@ -55,7 +62,6 @@ In addition, you'll want to specify a direction:
5562
- `.tooltipped-w`
5663
- `.tooltipped-nw`
5764

58-
Tooltip classes will conflict with Octicon classes, and as such, must go on a parent element instead of the icon.
5965

6066
```html
6167
<span class="tooltipped tooltipped-n border p-2 mb-2 mr-2 float-left" aria-label="This is the tooltip on the North side.">
@@ -84,7 +90,37 @@ Tooltip classes will conflict with Octicon classes, and as such, must go on a pa
8490
</span>
8591
```
8692

87-
#### Tooltips with multiple lines
93+
## Tooltip alignment
94+
Align tooltips to the left or right of an element, combined with a directional class to specify north or south.
95+
96+
```html
97+
<span class="tooltipped tooltipped-ne tooltipped-align-left-1 border p-2 mb-2 mr-2 float-left" aria-label="Tooltipped NE and aligned left.">
98+
Tooltip North East align left 1
99+
</span>
100+
<span class="tooltipped tooltipped-ne tooltipped-align-left-2 border p-2 mb-2 mr-2 float-left" aria-label="Tooltipped NE and aligned left.">
101+
Tooltip North East align left 2
102+
</span>
103+
<span class="tooltipped tooltipped-se tooltipped-align-left-1 border p-2 mb-2 mr-2 float-left" aria-label="Tooltipped SW and aigned left.">
104+
Tooltip South East align left 1
105+
</span>
106+
<span class="tooltipped tooltipped-se tooltipped-align-left-2 border p-2 mb-2 mr-2 float-left" aria-label="Tooltipped SW and aigned left.">
107+
Tooltip South East align left 2
108+
</span>
109+
<span class="tooltipped tooltipped-nw tooltipped-align-right-1 border p-2 mb-2 mr-2 float-left" aria-label="Tooltipped NW and aligned right.">
110+
Tooltip North West align right 1
111+
</span>
112+
<span class="tooltipped tooltipped-nw tooltipped-align-right-2 border p-2 mb-2 mr-2 float-left" aria-label="Tooltipped NW and aligned right.">
113+
Tooltip North West align right 2
114+
</span>
115+
<span class="tooltipped tooltipped-sw tooltipped-align-right-1 border p-2 mb-2 mr-2 float-left" aria-label="Tooltipped SE and aligned right.">
116+
Tooltip South West align right 1
117+
</span>
118+
<span class="tooltipped tooltipped-sw tooltipped-align-right-2 border p-2 mb-2 mr-2 float-left" aria-label="Tooltipped SE and aligned right.">
119+
Tooltip South West align right 2
120+
</span>
121+
```
122+
123+
## Tooltips with multiple lines
88124
Use `.tooltipped-multiline` when you have long content. This style has some limitations: you cannot pre-format the text with newlines, and tooltips are limited to a max-width of `250px`.
89125

90126

@@ -94,7 +130,7 @@ Use `.tooltipped-multiline` when you have long content. This style has some limi
94130
</span>
95131
```
96132

97-
#### Tooltips No Delay
133+
## Tooltips No Delay
98134

99135
By default the tooltips have a slight delay before appearing. This is to keep multiple tooltips in the UI from being distracting. There is a modifier class you can use to override this. `.tooltipped-no-delay`
100136

modules/primer-tooltips/lib/tooltips.scss

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
position: absolute;
88
z-index: 1000000;
99
display: none;
10-
padding: 5px $spacer-2;
10+
padding: 0.5em 0.75em;
1111
font: normal normal 11px/1.5 $body-font;
1212
-webkit-font-smoothing: subpixel-antialiased;
1313
color: $tooltip-text-color;
@@ -21,7 +21,7 @@
2121
pointer-events: none;
2222
content: attr(aria-label);
2323
background: $tooltip-background-color;
24-
border-radius: 3px;
24+
border-radius: $border-radius;
2525
opacity: 0;
2626
}
2727

@@ -35,7 +35,7 @@
3535
color: $tooltip-background-color;
3636
pointer-events: none;
3737
content: "";
38-
border: 5px solid transparent;
38+
border: 6px $border-style transparent;
3939
opacity: 0;
4040
}
4141

@@ -90,14 +90,14 @@
9090
&::after {
9191
top: 100%;
9292
right: 50%;
93-
margin-top: 5px;
93+
margin-top: 6px;
9494
}
9595

9696
&::before {
9797
top: auto;
9898
right: 50%;
99-
bottom: -5px;
100-
margin-right: -5px;
99+
bottom: -7px;
100+
margin-right: -6px;
101101
border-bottom-color: $tooltip-background-color;
102102
}
103103
}
@@ -106,12 +106,12 @@
106106
&::after {
107107
right: auto;
108108
left: 50%;
109-
margin-left: -15px;
109+
margin-left: -$spacer-3;
110110
}
111111
}
112112

113113
.tooltipped-sw::after {
114-
margin-right: -15px;
114+
margin-right: -$spacer-3;
115115
}
116116

117117
// Tooltips above the object
@@ -121,14 +121,14 @@
121121
&::after {
122122
right: 50%;
123123
bottom: 100%;
124-
margin-bottom: 5px;
124+
margin-bottom: 6px;
125125
}
126126

127127
&::before {
128-
top: -5px;
128+
top: -7px;
129129
right: 50%;
130130
bottom: auto;
131-
margin-right: -5px;
131+
margin-right: -6px;
132132
border-top-color: $tooltip-background-color;
133133
}
134134
}
@@ -137,12 +137,12 @@
137137
&::after {
138138
right: auto;
139139
left: 50%;
140-
margin-left: -15px;
140+
margin-left: -$spacer-3;
141141
}
142142
}
143143

144144
.tooltipped-nw::after {
145-
margin-right: -15px;
145+
margin-right: -$spacer-3;
146146
}
147147

148148
// Move the tooltip body to the center of the object.
@@ -156,15 +156,15 @@
156156
&::after {
157157
right: 100%;
158158
bottom: 50%;
159-
margin-right: 5px;
159+
margin-right: 6px;
160160
transform: translateY(50%);
161161
}
162162

163163
&::before {
164164
top: 50%;
165165
bottom: 50%;
166-
left: -5px;
167-
margin-top: -5px;
166+
left: -7px;
167+
margin-top: -6px;
168168
border-left-color: $tooltip-background-color;
169169
}
170170
}
@@ -174,19 +174,60 @@
174174
&::after {
175175
bottom: 50%;
176176
left: 100%;
177-
margin-left: 5px;
177+
margin-left: 6px;
178178
transform: translateY(50%);
179179
}
180180

181181
&::before {
182182
top: 50%;
183-
right: -5px;
183+
right: -7px;
184184
bottom: 50%;
185-
margin-top: -5px;
185+
margin-top: -6px;
186186
border-right-color: $tooltip-background-color;
187187
}
188188
}
189189

190+
// Tooltip align right and left
191+
.tooltipped-align-right-1,
192+
.tooltipped-align-right-2 {
193+
&::after {
194+
right: 0;
195+
margin-right: 0;
196+
}
197+
}
198+
199+
.tooltipped-align-right-1 {
200+
&::before {
201+
right: 10px;
202+
}
203+
}
204+
205+
.tooltipped-align-right-2 {
206+
&::before {
207+
right: 15px;
208+
}
209+
}
210+
211+
.tooltipped-align-left-1,
212+
.tooltipped-align-left-2, {
213+
&::after {
214+
left: 0;
215+
margin-left: 0;
216+
}
217+
}
218+
219+
.tooltipped-align-left-1 {
220+
&::before {
221+
left: 5px;
222+
}
223+
}
224+
225+
.tooltipped-align-left-2 {
226+
&::before {
227+
left: 10px;
228+
}
229+
}
230+
190231
// Multiline tooltips
191232
//
192233
// `.tooltipped-multiline` Add this class when you have long content.
@@ -270,10 +311,3 @@
270311
border-left-color: $background-color;
271312
}
272313
}
273-
274-
@include retina-media-query {
275-
.tooltipped-w::after {
276-
// weird bug on retina
277-
margin-right: 4.5px;
278-
}
279-
}

modules/primer-tooltips/stories.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import React from 'react'
2+
import { storiesOf } from '@storybook/react'
3+
4+
storiesOf('Tooltips', module)
5+
.add('tooltipped direction', () => (
6+
<div className='p-4'>
7+
<span className='tooltipped tooltipped-n border p-2 mb-2 mr-2 float-left' aria-label='This is the tooltip on the North side.'>
8+
Tooltip North
9+
</span>
10+
<span className='tooltipped tooltipped-ne border p-2 mb-2 mr-2 float-left' aria-label='This is the tooltip on the North East side.'>
11+
Tooltip North East
12+
</span>
13+
<span className='tooltipped tooltipped-e border p-2 mb-2 mr-2 float-left' aria-label='This is the tooltip on the East side.'>
14+
Tooltip East
15+
</span>
16+
<span className='tooltipped tooltipped-se border p-2 mb-2 mr-2 float-left' aria-label='This is the tooltip on the South East side.'>
17+
Tooltip South East
18+
</span>
19+
<span className='tooltipped tooltipped-s border p-2 mb-2 mr-2 float-left' aria-label='This is the tooltip on the South side.'>
20+
Tooltip South
21+
</span>
22+
<span className='tooltipped tooltipped-sw border p-2 mb-2 mr-2 float-left' aria-label='This is the tooltip on the South West side.'>
23+
Tooltip South West
24+
</span>
25+
<span className='tooltipped tooltipped-w border p-2 mb-2 mr-2 float-left' aria-label='This is the tooltip on the West side.'>
26+
Tooltip West
27+
</span>
28+
<span className='tooltipped tooltipped-nw border p-2 mb-2 mr-2 float-left' aria-label='This is the tooltip on the North West side.'>
29+
Tooltip North West
30+
</span>
31+
</div>
32+
))
33+
.add('tooltip aligned', () => (
34+
<div className='p-4'>
35+
<span className='tooltipped tooltipped-ne tooltipped-align-left-1 border p-2 mb-2 mr-2 float-left' aria-label='Tooltipped NE and aligned left.'>
36+
Tooltip North East align left 1
37+
</span>
38+
<span className='tooltipped tooltipped-ne tooltipped-align-left-2 border p-2 mb-2 mr-2 float-left' aria-label='Tooltipped NE and aligned left.'>
39+
Tooltip North East align left 2
40+
</span>
41+
<span className='tooltipped tooltipped-se tooltipped-align-left-1 border p-2 mb-2 mr-2 float-left' aria-label='Tooltipped SW and aigned left.'>
42+
Tooltip South East align left 1
43+
</span>
44+
<span className='tooltipped tooltipped-se tooltipped-align-left-2 border p-2 mb-2 mr-2 float-left' aria-label='Tooltipped SW and aigned left.'>
45+
Tooltip South East align left 2
46+
</span>
47+
<span className='tooltipped tooltipped-nw tooltipped-align-right-1 border p-2 mb-2 mr-2 float-left' aria-label='Tooltipped NW and aligned right.'>
48+
Tooltip North West align right 1
49+
</span>
50+
<span className='tooltipped tooltipped-nw tooltipped-align-right-2 border p-2 mb-2 mr-2 float-left' aria-label='Tooltipped NW and aligned right.'>
51+
Tooltip North West align right 2
52+
</span>
53+
<span className='tooltipped tooltipped-sw tooltipped-align-right-1 border p-2 mb-2 mr-2 float-left' aria-label='Tooltipped SE and aligned right.'>
54+
Tooltip South West align right 1
55+
</span>
56+
<span className='tooltipped tooltipped-sw tooltipped-align-right-2 border p-2 mb-2 mr-2 float-left' aria-label='Tooltipped SE and aligned right.'>
57+
Tooltip South West align right 2
58+
</span>
59+
</div>
60+
))
61+
.add('tootlipped-multiline', () => (
62+
<div className='p-6'>
63+
<span className='tooltipped tooltipped-multiline tooltipped-s border p-2 mr-2' aria-label='This is the tooltip with multiple lines. This is the tooltip with multiple lines.'>
64+
Tooltip with multiple lines
65+
</span>
66+
<span className='tooltipped tooltipped-multiline tooltipped-sw tooltipped-align-right-2 border p-2' aria-label='This is the tooltip with multiple lines. This is the tooltip with multiple lines.'>
67+
Tooltip with multiple lines
68+
</span>
69+
</div>
70+
))
71+
.add('tootlip no delay', () => (
72+
<div className='p-6'>
73+
<span className='tooltipped tooltipped-n tooltipped-no-delay border p-2' aria-label='This is a tooltip with no delay.'>
74+
Tooltip no delay
75+
</span>
76+
</div>
77+
))
78+
.add('tooltip on button', () => (
79+
<div className='p-6'>
80+
<button className='btn btn-secondary tooltipped tooltipped-n' aria-label='This is the tooltip on a button.'>Button</button>
81+
</div>
82+
))

0 commit comments

Comments
 (0)