Skip to content

Commit a5ea45c

Browse files
authored
Fix underline-opacity utility composition with themed colors (#42697)
underline-opacity hardcoded --link-color, so pairing it with a themed underline-color utility (or hovering) reset the underline back to the link color instead of fading the intended theme color. Route underline-color through a shared --underline-color custom property, same pattern as our bg/fg/border opacity utilities, and have underline-opacity read from it with currentcolor as a fallback.
1 parent 1a0c06e commit a5ea45c

4 files changed

Lines changed: 18 additions & 7 deletions

File tree

scss/_theme.scss

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,21 @@
4646
}
4747

4848
// Generate opacity values using color-mix()
49-
@function theme-opacity-values($color-var, $opacities: $util-opacity) {
49+
// $fallback lets the referenced $color-var fall back to another color (e.g. currentcolor)
50+
// when it hasn't been set by a companion color utility.
51+
@function theme-opacity-values($color-var, $fallback: null, $opacities: $util-opacity) {
5052
$result: ();
53+
// stylelint-disable-next-line scss/at-function-named-arguments, @stylistic/function-whitespace-after
54+
$color: if(sass($fallback): var($color-var, $fallback); else: var($color-var));
5155

5256
@each $key, $value in $opacities {
5357
@if $key == 100 {
5458
// For 100%, use direct variable reference (more efficient)
55-
$result: map.merge($result, ($key: var($color-var)));
59+
$result: map.merge($result, ($key: $color));
5660
} @else {
5761
// For other values, use color-mix()
5862
$percentage: $key * 1%;
59-
$result: map.merge($result, ($key: color-mix(in oklch, var($color-var) $percentage, transparent)));
63+
$result: map.merge($result, ($key: color-mix(in oklch, $color $percentage, transparent)));
6064
}
6165
}
6266

scss/_utilities.scss

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -803,15 +803,18 @@ $utilities: map.merge(
803803
)
804804
),
805805
"underline-color": (
806-
property: text-decoration-color,
806+
property: (
807+
"--underline-color": null,
808+
"text-decoration-color": var(--underline-color)
809+
),
807810
class: underline,
808811
values: theme-color-values("fg"),
809812
),
810813
"underline-opacity": (
811814
property: text-decoration-color,
812815
class: underline,
813816
state: hover,
814-
values: theme-opacity-values(--link-color)
817+
values: theme-opacity-values(--underline-color, currentcolor)
815818
),
816819
"underline-thickness": (
817820
property: text-decoration-thickness,

site/src/content/docs/helpers/icon-link.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Customize the icon link Sass variables to modify all icon link styles across you
7878

7979
Modify icon links with any of [our link utilities]([[docsref:/utilities/link/]]) for modifying underline color and offset.
8080

81-
<Example code={`<a class="icon-link icon-link-hover theme-success underline-success underline-25 underline-offset-3" href="#">
81+
<Example code={`<a class="icon-link icon-link-hover theme-success underline-success underline-30 hover:underline-80 underline-offset-3" href="#">
8282
Icon link
8383
<svg xmlns="http://www.w3.org/2000/svg" class="bi" viewBox="0 0 16 16" aria-hidden="true">
8484
<path d="M1 8a.5.5 0 0 1 .5-.5h11.793l-3.147-3.146a.5.5 0 0 1 .708-.708l4 4a.5.5 0 0 1 0 .708l-4 4a.5.5 0 0 1-.708-.708L13.293 8.5H1.5A.5.5 0 0 1 1 8z"/>

site/src/content/docs/utilities/text-decoration.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Change the underline’s color independent of the text color.
4040

4141
### Opacity
4242

43-
Change the underline’s opacity. Requires adding `.underline-{color}` to first set an `rgba()` color we use to then modify the alpha opacity.
43+
Change the underline’s opacity. Fades the current text color by default, or pair with `.underline-{color}` to first set a color that the opacity is then mixed against.
4444

4545
<Example code={`<p><a class="underline-10" href="#">Underline opacity 10</a></p>
4646
<p><a class="underline-20" href="#">Underline opacity 20</a></p>
@@ -53,6 +53,10 @@ Change the underline’s opacity. Requires adding `.underline-{color}` to first
5353
<p><a class="underline-90" href="#">Underline opacity 90</a></p>
5454
<p><a class="underline-100" href="#">Underline opacity 100</a></p>`} />
5555

56+
Pair an opacity class with a color class to fade that specific color instead of the default text color:
57+
58+
<Example code={`<a class="theme-success underline-success underline-30 hover:underline-80" href="#">Faded success underline</a>`} />
59+
5660
### Thickness
5761

5862
Change the thickness of the underline.

0 commit comments

Comments
 (0)