Skip to content

Conversation

@stephaniehobson
Copy link
Contributor

@stephaniehobson stephaniehobson commented Jul 23, 2025

Description

  • Removes :hover:visited styles for links
  • Removes text colour change on :focus for links (rely on focus ring instead)

  • I have documented this change in the design system.
  • I have recorded this change in CHANGELOG.md.

Issue

Fix #1071

Testing

Toggle through the various states using dev tools and make sure they're all displaying as intended.

http://localhost:3000/components/detail/links--default
http://localhost:3000/components/detail/button--primary
http://localhost:3000/components/detail/footer
http://localhost:3000/components/detail/notification-bar--warning

Hard-swap the files into bedrock and see if it breaks anything (if you turn off the Firefox redirects you can view Fxc content and skip testing springfield 🙂 )

It should fix the :focus state for buttons on this page: http://localhost:3000/en-US/about/manifesto/

@stephaniehobson stephaniehobson force-pushed the remove-hover-visited branch 2 times, most recently from 74df85d to 35fa5bf Compare July 23, 2025 23:07
.mzp-c-button,
a.mzp-c-button:link,
a.mzp-c-button:visited {
a.mzp-c-button {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The increased specificity was added in #1045 to address the problem where links were styled like buttons and then got focus.

This has been solved by removing the text colour change for :focus styles from the default :link styles.

@stephaniehobson stephaniehobson force-pushed the remove-hover-visited branch 2 times, most recently from aaf6ce2 to aa7d62f Compare July 24, 2025 04:23
color: $link-color;
text-decoration: underline;

&:visited {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:visited moves earlier in the source so is over-ridden by the hover, focus, and active styles that follow. We rely on the cascade to style a link when it's hovered instead of explicitly declaring :visited:hover styles.

}

&:hover,
&:focus,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declaring the colour change on focus was the root problem in #842

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could split the definition and keep the text-decoration styles for focus if we wanted but we also have the focus ring to indicate state.

@stephaniehobson stephaniehobson changed the title Remove :hover:visited styles (Fix #1071) Remove :hover:visited styles and decrease base link specificity (Fix #1071) Jul 25, 2025
reduce specificity in components
@stephaniehobson

This comment was marked as outdated.

@stephaniehobson stephaniehobson marked this pull request as ready for review July 28, 2025 20:46
color: $link-color;
text-decoration: underline;

&:where(:visited) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't decrease the specificity enough for :visited with re-arranging things alone.

I think using :where only on the visited links is good progressive enhancement. Older browsers will still be able to see and interact with links without any problem. Newer browsers get the visual indication of visited as well.

Maybe this is the best of both worlds from @maureenlholland's #1054

@stephaniehobson stephaniehobson added Review: S Code review time: 30 mins to 1 hour Needs:Review 👋 Ready for Developer Review labels Aug 1, 2025
Copy link
Collaborator

@maureenlholland maureenlholland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+wc 🎉 this is looking much cleaner - nothing blocking: minor typo and a suggestion on possibly making the button component selector even simpler

tested on moz and fxc pages in bedrock (thanks for the disable redirect tip), fixes the color contrast issues seen on manifesto button and account promo links (i.e. on http://localhost:8000/fr/firefox/browsers/mobile/)

account-promo

color: $link-color;
text-decoration: underline;

&:where(:visited) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (non-blocking) Might be worth putting the comment in code so it's clear why :where is only used in this case

a.mzp-c-button:link,
a.mzp-c-button:visited {
.mzp-c-button, /* stylelint-disable-line no-duplicate-selectors */
a.mzp-c-button {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (non-blocking): in the interest of keeping specificity as low as possible, is it possible to remove the prepended a selector too? the button class should overrule the base element

Suggested change
a.mzp-c-button {
{

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of :where() on link visited state reduces specificity to element selector

We should be able to rely solely on .mzp-c-button class selector for button styles (regardless of whether underlying element is button or link). Link element styles only use color, background-color, and text-decoration properties, so we could remove the prepended a from Button shape and style selector too (L76)

link-button overruling-element-selector

$link-color-hover-inverse: tokens.$color-blue-05;
$link-color-hover: tokens.$color-link-hover;
$link-color-inverse: tokens.$color-blue-10;
$link-color-visited-hover-inverse: tokens.$color-violet-05;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 🧹 🧹

stephaniehobson and others added 2 commits August 11, 2025 11:55
@stephaniehobson stephaniehobson merged commit 111a12b into main Aug 11, 2025
1 check passed
@stephaniehobson stephaniehobson deleted the remove-hover-visited branch August 11, 2025 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs:Review 👋 Ready for Developer Review Review: S Code review time: 30 mins to 1 hour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove :hover:visited styles

3 participants