Skip to content

Commit

Permalink
fix(button, fab): Ensure elevation is correct when focused and hovering
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 500032153
  • Loading branch information
dfreedm authored and copybara-github committed Jan 6, 2023
1 parent bab6ebc commit 6e0775d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 37 deletions.
58 changes: 30 additions & 28 deletions button/lib/_elevation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,40 @@
surface-tint-color: var(--_container-surface-tint-layer-color)
)
);
}

.md3-button:hover {
@include elevation.theme(
(
level: var(--_hover-container-elevation),
)
);
}
// apply elevation in order of focused, hovered, pressed, disabled
// this ensures a button will have hover elevation after being focused
&:focus {
@include elevation.theme(
(
level: var(--_focus-container-elevation),
)
);
}

.md3-button:focus {
@include elevation.theme(
(
level: var(--_focus-container-elevation),
)
);
}
&:hover {
@include elevation.theme(
(
level: var(--_hover-container-elevation),
)
);
}

.md3-button:active {
@include elevation.theme(
(
level: var(--_pressed-container-elevation),
)
);
}
&:active {
@include elevation.theme(
(
level: var(--_pressed-container-elevation),
)
);
}

.md3-button:disabled {
@include elevation.theme(
(
level: var(--_disabled-container-elevation),
)
);
&:disabled {
@include elevation.theme(
(
level: var(--_disabled-container-elevation),
)
);
}
}
}

Expand Down
20 changes: 11 additions & 9 deletions fab/lib/_shared.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,35 +81,37 @@
);
}

&:hover {
cursor: pointer;

// apply elevation in order of focused, hovered, pressed
// this ensures a button will have hover elevation after being focused
&:focus {
@include elevation.theme(
(
level: var(--_hover-container-elevation),
level: var(--_focus-container-elevation),
)
);

&.md3-fab--lowered {
@include elevation.theme(
(
level: var(--_lowered-hover-container-elevation),
level: var(--_lowered-focus-container-elevation),
)
);
}
}

&:focus {
&:hover {
cursor: pointer;

@include elevation.theme(
(
level: var(--_focus-container-elevation),
level: var(--_hover-container-elevation),
)
);

&.md3-fab--lowered {
@include elevation.theme(
(
level: var(--_lowered-focus-container-elevation),
level: var(--_lowered-hover-container-elevation),
)
);
}
Expand Down Expand Up @@ -158,7 +160,7 @@
@include touch-target.touch-target();
}

::slotted(*),
.md3-fab__icon ::slotted(*),
.md3-fab__icon {
color: var(--_icon-color);
font-size: var(--_icon-size);
Expand Down

0 comments on commit 6e0775d

Please sign in to comment.