Skip to content

Commit 815daff

Browse files
vdepizzoljonrohan
andauthored
[ActionList] Add hover to aria-current elements and other micro interactions (#1870)
* Add hover to aria-current element Also included a quick transition for subGroup elements * Add touch-action, remove tap highlight, and more Also: - Avoided sticky hover on touch devices with hover:hover media query - removed pointer: fine specificity to hover media queries - simplified reduce-motion media query * Keep parent above subGroup during transition * Keep out-of-bound indicator line visible * Please stylelint * Create six-avocados-promise.md Co-authored-by: Jon Rohan <yes@jonrohan.codes>
1 parent b7e6087 commit 815daff

File tree

2 files changed

+61
-21
lines changed

2 files changed

+61
-21
lines changed

.changeset/six-avocados-promise.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/css": patch
3+
---
4+
5+
[ActionList] Add hover to `aria-current` elements and other micro interactions

src/actionlist/action-list-item.scss

Lines changed: 56 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// stylelint-disable max-nesting-depth, selector-max-specificity
2+
13
@mixin focusOutline {
24
position: relative;
35
z-index: 1;
@@ -22,6 +24,8 @@
2224
list-style: none;
2325
background-color: transparent;
2426
border-radius: $border-radius;
27+
touch-action: manipulation;
28+
-webkit-tap-highlight-color: transparent;
2529

2630
&:hover,
2731
&:active {
@@ -35,9 +39,11 @@
3539

3640
// only hover li without list as children
3741
&:not(.ActionList-item--hasSubItem) {
38-
&:hover {
39-
cursor: pointer;
40-
background-color: var(--color-action-list-item-default-hover-bg);
42+
@media (hover: hover) {
43+
&:hover {
44+
cursor: pointer;
45+
background-color: var(--color-action-list-item-default-hover-bg);
46+
}
4147
}
4248

4349
&:active {
@@ -49,13 +55,11 @@
4955

5056
// stylelint-disable primer/box-shadow
5157
@keyframes ActionList-item-active-bg {
52-
// stylelint-disable-next-line max-nesting-depth
5358
50% {
5459
box-shadow: inset 0 0 0 rgba(#000, 0.04);
5560
transform: scale(1);
5661
}
5762

58-
// stylelint-disable-next-line max-nesting-depth
5963
100% {
6064
box-shadow: inset 0 3px 9px rgba(#000, 0.04);
6165
transform: scale(0.97);
@@ -64,10 +68,18 @@
6468
// stylelint-enable primer/box-shadow
6569
}
6670

67-
&:hover,
71+
// hide dividers
72+
73+
@media (hover: hover) {
74+
&:hover {
75+
.ActionList-item-label::before,
76+
+ .ActionList-item .ActionList-item-label::before {
77+
visibility: hidden;
78+
}
79+
}
80+
}
81+
// stylelint-disable-next-line no-duplicate-selectors
6882
&:active {
69-
// hide dividers
70-
// stylelint-disable-next-line selector-max-specificity
7183
.ActionList-item-label::before,
7284
+ .ActionList-item .ActionList-item-label::before {
7385
visibility: hidden;
@@ -80,8 +92,16 @@
8092
&.ActionList-item--hasSubItem {
8193
// first child
8294
> .ActionList-content {
83-
&:hover {
84-
background-color: var(--color-action-list-item-default-hover-bg);
95+
z-index: 1;
96+
97+
@media (hover: hover) {
98+
&:hover {
99+
background-color: var(--color-action-list-item-default-hover-bg);
100+
}
101+
}
102+
103+
&:active {
104+
background-color: var(--color-action-list-item-default-active-bg);
85105
}
86106
}
87107
}
@@ -98,7 +118,12 @@
98118
&:not(.ActionList-item--danger) {
99119
background: var(--color-action-list-item-default-selected-bg);
100120

101-
// stylelint-disable-next-line selector-max-specificity
121+
@media (hover: hover) {
122+
&:hover {
123+
background-color: var(--color-action-list-item-default-hover-bg);
124+
}
125+
}
126+
102127
&::before,
103128
+ .ActionList-item::before {
104129
visibility: hidden;
@@ -117,30 +142,34 @@
117142
// target items inside expanded subgroups
118143
&[aria-expanded] {
119144
.ActionList--subGroup {
145+
@media screen and (prefers-reduced-motion: no-preference) {
146+
transition: opacity 160ms cubic-bezier(0.25, 1, 0.5, 1), transform 160ms cubic-bezier(0.25, 1, 0.5, 1);
147+
}
148+
120149
.ActionList-content {
121150
padding-left: $spacer-4;
122151
}
123152
}
124153

125154
// has 16px leading visual
126155
.ActionList-content--visual16 + .ActionList--subGroup {
127-
// stylelint-disable-next-line selector-max-compound-selectors, selector-max-specificity
156+
// stylelint-disable-next-line selector-max-compound-selectors
128157
.ActionList-content {
129158
padding-left: $spacer-5;
130159
}
131160
}
132161

133162
// has 20px leading visual
134163
.ActionList-content--visual20 + .ActionList--subGroup {
135-
// stylelint-disable-next-line selector-max-compound-selectors, selector-max-specificity
164+
// stylelint-disable-next-line selector-max-compound-selectors
136165
.ActionList-content {
137166
padding-left: $spacer-2 * 4.5; // 36px
138167
}
139168
}
140169

141170
// has 24px leading visual
142171
.ActionList-content--visual24 + .ActionList--subGroup {
143-
// stylelint-disable-next-line selector-max-compound-selectors, selector-max-specificity
172+
// stylelint-disable-next-line selector-max-compound-selectors
144173
.ActionList-content {
145174
padding-left: $spacer-6;
146175
}
@@ -154,11 +183,14 @@
154183
}
155184

156185
.ActionList--subGroup {
157-
display: block;
186+
height: auto;
187+
overflow: visible;
188+
visibility: visible;
189+
opacity: 1;
190+
transform: translateY(0);
158191
}
159192

160193
&.ActionList-item--hasActiveSubItem {
161-
// stylelint-disable-next-line selector-max-specificity
162194
> .ActionList-content > .ActionList-item-label {
163195
font-weight: $font-weight-bold;
164196
}
@@ -172,7 +204,11 @@
172204
}
173205

174206
.ActionList--subGroup {
175-
display: none;
207+
height: 0;
208+
overflow: hidden;
209+
visibility: hidden;
210+
opacity: 0;
211+
transform: translateY(-$spacer-3);
176212
}
177213

178214
// show active indicator on parent collapse if child is active
@@ -183,7 +219,6 @@
183219
font-weight: $font-weight-bold;
184220
}
185221

186-
// stylelint-disable-next-line selector-max-specificity
187222
&::before,
188223
+ .ActionList-item::before {
189224
visibility: hidden;
@@ -300,11 +335,10 @@
300335
color: var(--color-danger-fg);
301336
}
302337

303-
@media (hover: hover) and (pointer: fine) {
338+
@media (hover: hover) {
304339
&:hover {
305340
background: var(--color-action-list-item-danger-hover-bg);
306341

307-
// stylelint-disable-next-line max-nesting-depth
308342
.ActionList-item-label {
309343
color: var(--color-action-list-item-danger-hover-text);
310344
}
@@ -327,7 +361,7 @@
327361
fill: var(--color-primer-fg-disabled);
328362
}
329363

330-
@media (hover: hover) and (pointer: fine) {
364+
@media (hover: hover) {
331365
&:hover {
332366
cursor: not-allowed;
333367
background-color: transparent;
@@ -352,6 +386,7 @@
352386
font-weight: $font-weight-normal;
353387
color: var(--color-fg-default);
354388
user-select: none;
389+
touch-action: manipulation;
355390
border-radius: $border-radius;
356391
transition: $actionList-item-bg-transition;
357392
grid-template-rows: min-content;

0 commit comments

Comments
 (0)