Skip to content

Commit a6d79b0

Browse files
fix(Card): Prevent other links than the Card Link from stretching (#1898)
Co-authored-by: Aram <37216945+alimpens@users.noreply.github.com>
1 parent 190b588 commit a6d79b0

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

packages/css/src/components/card/card.scss

+19-22
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,15 @@
77
display: grid;
88
gap: var(--ams-card-gap);
99
outline-offset: var(--ams-card-outline-offset);
10-
position: relative;
10+
position: relative; // Allows stretching the card link below.
1111
touch-action: manipulation;
1212

13-
/* Set native outline on card if card has focus visible within */
13+
// Set native outline to Card if it has a visible focus inside.
1414
&:has(:focus-visible) {
1515
outline-color: -webkit-focus-ring-color;
1616
outline-style: auto;
1717
outline-width: 0.0625rem;
1818
}
19-
20-
/*
21-
Remove link focus outline only if :has is supported,
22-
which means the outline on the whole card is set
23-
*/
24-
&:has(:focus-visible) a:focus {
25-
outline: none;
26-
}
27-
28-
/*
29-
This trick, together with position: relative on the outer wrapper, makes the whole card clickable.
30-
Taken from https://inclusive-components.design/cards/
31-
*/
32-
a::after {
33-
content: "";
34-
display: block;
35-
inset-block: 0;
36-
inset-inline: 0;
37-
position: absolute;
38-
}
3919
}
4020

4121
.ams-card__heading-group {
@@ -50,8 +30,25 @@
5030
text-decoration-thickness: var(--ams-card-link-text-decoration-thickness);
5131
text-underline-offset: var(--ams-card-link-text-underline-offset);
5232

33+
// Make the whole Card clickable by making the link cover its entire area.
34+
// Source: https://inclusive-components.design/cards/
35+
&::after {
36+
content: "";
37+
display: block;
38+
inset-block: 0;
39+
inset-inline: 0;
40+
position: absolute;
41+
}
42+
5343
&:hover {
5444
color: var(--ams-card-link-hover-color);
5545
text-decoration-line: var(--ams-card-link-hover-text-decoration-line);
5646
}
47+
48+
// Remove the outline from the link; it’s already on the Card.
49+
// Reuses the `.ams-card:has(:focus-visible)` selector above, so that
50+
// browsers that support it apply both styles, while those that don’t apply neither.
51+
.ams-card:has(:focus-visible) &:focus {
52+
outline: none;
53+
}
5754
}

0 commit comments

Comments
 (0)