Skip to content

Commit

Permalink
[ActionList] Add hover to aria-current elements and other micro int…
Browse files Browse the repository at this point in the history
…eractions (#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 <[email protected]>
  • Loading branch information
vdepizzol and jonrohan authored Jan 12, 2022
1 parent b7e6087 commit 815daff
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/six-avocados-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/css": patch
---

[ActionList] Add hover to `aria-current` elements and other micro interactions
77 changes: 56 additions & 21 deletions src/actionlist/action-list-item.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// stylelint-disable max-nesting-depth, selector-max-specificity

@mixin focusOutline {
position: relative;
z-index: 1;
Expand All @@ -22,6 +24,8 @@
list-style: none;
background-color: transparent;
border-radius: $border-radius;
touch-action: manipulation;
-webkit-tap-highlight-color: transparent;

&:hover,
&:active {
Expand All @@ -35,9 +39,11 @@

// only hover li without list as children
&:not(.ActionList-item--hasSubItem) {
&:hover {
cursor: pointer;
background-color: var(--color-action-list-item-default-hover-bg);
@media (hover: hover) {
&:hover {
cursor: pointer;
background-color: var(--color-action-list-item-default-hover-bg);
}
}

&:active {
Expand All @@ -49,13 +55,11 @@

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

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

&:hover,
// hide dividers

@media (hover: hover) {
&:hover {
.ActionList-item-label::before,
+ .ActionList-item .ActionList-item-label::before {
visibility: hidden;
}
}
}
// stylelint-disable-next-line no-duplicate-selectors
&:active {
// hide dividers
// stylelint-disable-next-line selector-max-specificity
.ActionList-item-label::before,
+ .ActionList-item .ActionList-item-label::before {
visibility: hidden;
Expand All @@ -80,8 +92,16 @@
&.ActionList-item--hasSubItem {
// first child
> .ActionList-content {
&:hover {
background-color: var(--color-action-list-item-default-hover-bg);
z-index: 1;

@media (hover: hover) {
&:hover {
background-color: var(--color-action-list-item-default-hover-bg);
}
}

&:active {
background-color: var(--color-action-list-item-default-active-bg);
}
}
}
Expand All @@ -98,7 +118,12 @@
&:not(.ActionList-item--danger) {
background: var(--color-action-list-item-default-selected-bg);

// stylelint-disable-next-line selector-max-specificity
@media (hover: hover) {
&:hover {
background-color: var(--color-action-list-item-default-hover-bg);
}
}

&::before,
+ .ActionList-item::before {
visibility: hidden;
Expand All @@ -117,30 +142,34 @@
// target items inside expanded subgroups
&[aria-expanded] {
.ActionList--subGroup {
@media screen and (prefers-reduced-motion: no-preference) {
transition: opacity 160ms cubic-bezier(0.25, 1, 0.5, 1), transform 160ms cubic-bezier(0.25, 1, 0.5, 1);
}

.ActionList-content {
padding-left: $spacer-4;
}
}

// has 16px leading visual
.ActionList-content--visual16 + .ActionList--subGroup {
// stylelint-disable-next-line selector-max-compound-selectors, selector-max-specificity
// stylelint-disable-next-line selector-max-compound-selectors
.ActionList-content {
padding-left: $spacer-5;
}
}

// has 20px leading visual
.ActionList-content--visual20 + .ActionList--subGroup {
// stylelint-disable-next-line selector-max-compound-selectors, selector-max-specificity
// stylelint-disable-next-line selector-max-compound-selectors
.ActionList-content {
padding-left: $spacer-2 * 4.5; // 36px
}
}

// has 24px leading visual
.ActionList-content--visual24 + .ActionList--subGroup {
// stylelint-disable-next-line selector-max-compound-selectors, selector-max-specificity
// stylelint-disable-next-line selector-max-compound-selectors
.ActionList-content {
padding-left: $spacer-6;
}
Expand All @@ -154,11 +183,14 @@
}

.ActionList--subGroup {
display: block;
height: auto;
overflow: visible;
visibility: visible;
opacity: 1;
transform: translateY(0);
}

&.ActionList-item--hasActiveSubItem {
// stylelint-disable-next-line selector-max-specificity
> .ActionList-content > .ActionList-item-label {
font-weight: $font-weight-bold;
}
Expand All @@ -172,7 +204,11 @@
}

.ActionList--subGroup {
display: none;
height: 0;
overflow: hidden;
visibility: hidden;
opacity: 0;
transform: translateY(-$spacer-3);
}

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

// stylelint-disable-next-line selector-max-specificity
&::before,
+ .ActionList-item::before {
visibility: hidden;
Expand Down Expand Up @@ -300,11 +335,10 @@
color: var(--color-danger-fg);
}

@media (hover: hover) and (pointer: fine) {
@media (hover: hover) {
&:hover {
background: var(--color-action-list-item-danger-hover-bg);

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

@media (hover: hover) and (pointer: fine) {
@media (hover: hover) {
&:hover {
cursor: not-allowed;
background-color: transparent;
Expand All @@ -352,6 +386,7 @@
font-weight: $font-weight-normal;
color: var(--color-fg-default);
user-select: none;
touch-action: manipulation;
border-radius: $border-radius;
transition: $actionList-item-bg-transition;
grid-template-rows: min-content;
Expand Down

0 comments on commit 815daff

Please sign in to comment.