Skip to content

Commit

Permalink
Merge pull request #2877 from db-ui/2856-refactorscss-improve-selecto…
Browse files Browse the repository at this point in the history
…rs-by-grouping

refactor: optimized selectors
  • Loading branch information
mfranzke authored Jul 23, 2024
2 parents 87a4507 + 8099993 commit 67e957e
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
%sub-navi-handler-desktop {
// show sub-navigation on hover
@include screen-sizes.screen("md") {
&:hover,
&:focus-visible {
&:is(:hover, :focus-visible) {
~ .db-sub-navigation {
visibility: visible;
}
Expand Down Expand Up @@ -203,8 +202,7 @@
inset-inline-start: 100%;
}

&:hover,
&:focus-within {
&:is(:hover, :focus-within) {
visibility: visible;
}

Expand Down
26 changes: 16 additions & 10 deletions packages/components/src/components/navigation/navigation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@
}
}

&:hover,
&:focus-visible,
&:has(~ .db-sub-navigation:hover),
&:has(~ .db-sub-navigation:focus-visible),
&:has(~ .db-sub-navigation:focus-within) {
&:is(:hover, :focus-visible),
&:has(
~ .db-sub-navigation:is(
:hover,
:focus-visible,
:focus-within
)
) {
&::after {
transform: form-components.$dropdown-icon-transform;
}
Expand All @@ -62,11 +65,14 @@
--db-icon-margin-start: auto;
}

&:hover,
&:focus-visible,
&:has(~ .db-sub-navigation:hover),
&:has(~ .db-sub-navigation:focus-visible),
&:has(~ .db-sub-navigation:focus-within) {
&:is(:hover, :focus-visible),
:has(
~ .db-sub-navigation:is(
:hover,
:focus-visible,
:focus-within
)
) {
&::after {
transform: none;
}
Expand Down
4 changes: 1 addition & 3 deletions packages/components/src/components/popover/popover.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
.db-popover {
position: relative;

&[data-e2e-hover="true"],
&:hover,
&:focus-within {
&:is([data-e2e-hover="true"], :hover, :focus-within) {
> article:not([data-open="false"]) {
@extend %show-popover;
}
Expand Down
8 changes: 2 additions & 6 deletions packages/components/src/components/tag/tag.scss
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@

&:checked {
&,
&:not(:disabled):hover,
&:not(:disabled):focus,
&:not(:disabled):active {
&:not(:disabled):is(:hover, :focus, :active) {
background-color: colors.$db-brand-bg-transparent-full-enabled;
}

Expand All @@ -148,9 +146,7 @@
}

.db-link {
&:hover,
&:focus,
&:active {
&:is(:hover, :focus, :active) {
color: inherit;
}
}
Expand Down
6 changes: 2 additions & 4 deletions packages/components/src/components/textarea/textarea.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
}

&[data-variant="floating"] {
&:has(textarea:focus-within),
&:has(textarea:not(:placeholder-shown)) {
&:has(textarea:is(:focus-within, :not(:placeholder-shown))) {
&::before {
@extend %default-transition;

Expand All @@ -77,8 +76,7 @@
background-color: colors.$db-current-color-bg-lvl-1-enabled !important;
}

&:has(textarea:not(:disabled):hover),
&:has(textarea:not(:disabled):focus) {
&:has(textarea:not(:disabled):is(:hover, :focus)) {
&::after {
background-color: colors.$db-current-color-bg-transparent-hover;
}
Expand Down
8 changes: 5 additions & 3 deletions packages/components/src/styles/_form-components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ $check-border-size: min(#{variables.$db-border-height-2xs}, 2px);
}
}

&:has(#{$selector}:focus-within),
&:has(#{$selector}:is(input, textarea):not(:placeholder-shown)),
&:has(> select option:checked:not([hidden])) {
&:has(
#{$selector}:focus-within,
#{$selector}:is(input, textarea):not(:placeholder-shown),
> select option:checked:not([hidden])
) {
label {
@extend %db-overwrite-font-size-2xs;

Expand Down
6 changes: 2 additions & 4 deletions packages/components/src/styles/_scrollbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ $scrollbar-width: helpers.px-to-rem(8);
border-start-end-radius: variables.$db-border-radius-xs;
}

&:hover,
&:focus {
&:is(:hover, :focus) {
&::-webkit-scrollbar-track,
&::-webkit-scrollbar-button:single-button {
background-color: colors.$db-current-color-bg-transparent-hover;
Expand Down Expand Up @@ -48,8 +47,7 @@ $scrollbar-width: helpers.px-to-rem(8);
background-position: center;
block-size: form-components.$floating-label-size;

&:hover,
&:focus {
&:is(:hover, :focus) {
background-color: colors.$db-current-color-bg-transparent-hover;
}

Expand Down
4 changes: 1 addition & 3 deletions packages/components/src/styles/_tag-components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ $interactive-selectors: "label, button:not(.db-tab-remove-button), a";
// radio should have bg-lvl-3 (checked) without hover/pressed
label:has(input[type="radio"]:checked) {
&,
&:hover,
&:focus,
&:active {
&:is(:hover, :focus, :active) {
background-color: colors.$db-current-color-bg-lvl-3-enabled;
}
}
Expand Down

0 comments on commit 67e957e

Please sign in to comment.