Improve touch like hover on devices without mouse
This commit improves mobile support. `:hover` CSS selector is not mobile friendly because there is typically no mouse support on mobile. This commit make hover behavior to become active during touch on mobile. `:hover` selector is emulated on mobile devices. But this emulated behavior is not desired. When emulated, the CSS style gets attached when starting touching but does not get removed after stopping touching. This sticky behavior is undesired. This commit solve this issue by using Saas mixing that uses `:active` selector instead of `:hover` when `:hover` is not really supported but emulated.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
@use "@/presentation/assets/styles/colors" as *;
|
||||
@use "@/presentation/assets/styles/fonts" as *;
|
||||
|
||||
@use "@/presentation/assets/styles/mixins" as *;
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
@@ -14,7 +14,7 @@ a {
|
||||
color:inherit;
|
||||
text-decoration: underline;
|
||||
cursor: pointer;
|
||||
&:hover {
|
||||
@include hover-or-touch {
|
||||
color: $color-primary;
|
||||
}
|
||||
}
|
||||
|
||||
16
src/presentation/assets/styles/_mixins.scss
Normal file
16
src/presentation/assets/styles/_mixins.scss
Normal file
@@ -0,0 +1,16 @@
|
||||
@mixin hover-or-touch($selector-suffix: '', $selector-prefix: '&') {
|
||||
@media (hover: hover) {
|
||||
/* We only do this if hover is truly supported; otherwise the emulator in mobile
|
||||
keeps hovered style in-place even after touching, making it sticky. */
|
||||
#{$selector-prefix}:hover #{$selector-suffix} {
|
||||
@content;
|
||||
}
|
||||
}
|
||||
@media (hover: none) {
|
||||
/* We only do this if hover is not supported,otherwise the desktop behavior is not
|
||||
as desired; it does not get activated on hover but only during click/touch. */
|
||||
#{$selector-prefix}:active #{$selector-suffix} {
|
||||
@content;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
@forward "./media";
|
||||
@forward "./colors";
|
||||
@forward "./globals";
|
||||
@forward "./mixins";
|
||||
|
||||
@forward "./components/card";
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Overrides base styling for LiquorTree
|
||||
@use "@/presentation/assets/styles/colors" as *;
|
||||
@use "@/presentation/assets/styles/mixins" as *;
|
||||
|
||||
$color-tree-bg : $color-primary-darker;
|
||||
$color-node-arrow : $color-on-primary;
|
||||
@@ -23,9 +24,10 @@ $color-node-checkbox-tick-checked : $color-on-secondary;
|
||||
text-transform: uppercase;
|
||||
font-size: 1.5em;
|
||||
}
|
||||
&:hover {
|
||||
@include hover-or-touch {
|
||||
background: $color-node-hover-bg !important;
|
||||
}
|
||||
background: $color-tree-bg !important; // If not styled, it gets white background on mobile.
|
||||
}
|
||||
&.selected { // When using keyboard navigation it highlights current item and its child items
|
||||
background: $color-node-keyboard-bg;
|
||||
|
||||
Reference in New Issue
Block a user