Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Card): Prevent other links than the Card Link from stretching #1898

Merged
merged 6 commits into from
Mar 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions packages/css/src/components/card/card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,15 @@
display: grid;
gap: var(--ams-card-gap);
outline-offset: var(--ams-card-outline-offset);
position: relative;
position: relative; // Allows stretching the card link below.
touch-action: manipulation;

/* Set native outline on card if card has focus visible within */
// Set native outline to Card if it has a visible focus inside.
&:has(:focus-visible) {
outline-color: -webkit-focus-ring-color;
outline-style: auto;
outline-width: 0.0625rem;
}

/*
Remove link focus outline only if :has is supported,
which means the outline on the whole card is set
*/
&:has(:focus-visible) a:focus {
outline: none;
}

/*
This trick, together with position: relative on the outer wrapper, makes the whole card clickable.
Taken from https://inclusive-components.design/cards/
*/
a::after {
content: "";
display: block;
inset-block: 0;
inset-inline: 0;
position: absolute;
}
}

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

// Make the whole Card clickable by making the link cover its entire area.
// Source: https://inclusive-components.design/cards/
&::after {
content: "";
display: block;
inset-block: 0;
inset-inline: 0;
position: absolute;
}

&:hover {
color: var(--ams-card-link-hover-color);
text-decoration-line: var(--ams-card-link-hover-text-decoration-line);
}

// Remove the outline from the link; it’s already on the Card.
// Reuses the `.ams-card:has(:focus-visible)` selector above, so that
// browsers that support it apply both styles, while those that don’t apply neither.
.ams-card:has(:focus-visible) &:focus {
outline: none;
}
}