Skip to content

fix(switch): active down state specificity #3767

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

Open
wants to merge 10 commits into
base: spectrum-two
Choose a base branch
from

Conversation

saashapina
Copy link
Collaborator

Description

CSS-1176

RE

This looks like the regression was caused by the postcss plugin that adds @media (hover: hover). In the dist, it moves the hover CSS near the end off the CSS, changing its intended specificity from where it appears in the code; :hover is written to be before :active and I can see that the active state works correctly if postcss-hover-media-feature is temporarily disabled.

  • Adds specificity to active down state to maintain active down state styles when active.

Note:We should consider conducting an audit to check for any additional hover specificity regressions introduced by this plugin.

How and where has this been tested?

Please tag yourself on the tests you've marked complete to confirm the tests have been run by someone other than the author.

Validation steps

Regression testing

Validate:

  1. The documentation pages for at least two other components are still loading, including:
  • The pages render correctly, are accessible, and are responsive.
  1. If components have been modified, VRTs have been run on this branch:
  • VRTs have been run and looked at.
  • Any VRT changes have been accepted (by reviewer and/or PR author), or there are no changes.

Screenshots

To-do list

  • I have read the contribution guidelines.
  • I have updated relevant storybook stories and templates.
  • I have tested these changes in Windows High Contrast mode.
  • If my change impacts other components, I have tested to make sure they don't break.
  • If my change impacts documentation, I have updated the documentation accordingly.
  • ✨ This pull request is ready to merge. ✨

Copy link

changeset-bot bot commented May 16, 2025

🦋 Changeset detected

Latest commit: 52a70a4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@spectrum-css/switch Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented May 16, 2025

🚀 Deployed on https://pr-3767--spectrum-css.netlify.app

github-actions[bot]

This comment was marked as resolved.

Copy link
Contributor

github-actions bot commented May 16, 2025

File metrics

Summary

Total size: 1.41 MB*

Package Size Minified Gzipped
switch 25.68 KB 24.51 KB 2.75 KB

switch

Filename Head Minified Gzipped Compared to base
index.css 25.68 KB 24.51 KB 2.75 KB 🔴 ⬆ 1.00 KB
metadata.json 13.54 KB - - 🔴 ⬆ 0.86 KB
* Size is the sum of all main files for packages in the library.
* An ASCII character in UTF-8 is 8 bits or 1 byte.

@saashapina saashapina force-pushed the saashapina/fix-switch-down-state branch from 29c083f to f23344a Compare May 19, 2025 13:47
github-actions[bot]

This comment was marked as outdated.

@saashapina saashapina force-pushed the saashapina/fix-switch-down-state branch 2 times, most recently from 2bfb96b to 7465ca5 Compare May 19, 2025 15:58
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

markdownlint-fix

[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-menu-item-min-height",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-menu-item-spacing-multiplier",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-menu-item-top-edge-to-text",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-menu-item-value-color-default",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-menu-section-header-color",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-menu-section-header-min-width"


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-blue-800",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-border-width-200",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-component-top-to-text-100",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-corner-radius-100",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-focus-indicator-color",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-focus-indicator-thickness",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-gray-1000-rgb",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-navigational-indicator-top-to-back-icon-extra-large",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-spacing-100",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-text-to-visual-75",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-transparent-black-200-opacity",


[markdownlint-fix] reported by reviewdog 🐶

".spectrum-Swatch--lightBorder .spectrum-Swatch-fill:before",
".spectrum-Swatch--noBorder .spectrum-Swatch-fill:before",


[markdownlint-fix] reported by reviewdog 🐶

".spectrum-Swatch--sizeM",


[markdownlint-fix] reported by reviewdog 🐶

".spectrum-Swatch-image",


[markdownlint-fix] reported by reviewdog 🐶

".spectrum-Swatch-mixedValueIcon",


[markdownlint-fix] reported by reviewdog 🐶

".spectrum-Swatch.is-mixedValue .spectrum-Swatch-fill",


[markdownlint-fix] reported by reviewdog 🐶

".spectrum-Swatch.is-mixedValue .spectrum-Swatch-mixedValueIcon",
".spectrum-Swatch.is-nothing .spectrum-Swatch-fill",
".spectrum-Swatch.is-nothing .spectrum-Swatch-fill:after",
".spectrum-Swatch.is-nothing.spectrum-Swatch--rectangle .spectrum-Swatch-fill:after",


[markdownlint-fix] reported by reviewdog 🐶

".spectrum-Swatch:after",


[markdownlint-fix] reported by reviewdog 🐶

".spectrum-Swatch:focus-visible:after",


[markdownlint-fix] reported by reviewdog 🐶

"--mod-animation-duration-100",


[markdownlint-fix] reported by reviewdog 🐶

"--mod-swatch-border-color",


[markdownlint-fix] reported by reviewdog 🐶

"--mod-swatch-border-color-light",


[markdownlint-fix] reported by reviewdog 🐶

"--mod-swatch-border-radius",


[markdownlint-fix] reported by reviewdog 🐶

"--mod-swatch-focus-indicator-border-radius",


[markdownlint-fix] reported by reviewdog 🐶

"--mod-swatch-inner-border-color-selected",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-swatch-border-color",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-swatch-border-color-light",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-swatch-border-radius",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-swatch-dash-icon-color",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-swatch-focus-indicator-border-radius",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-swatch-inner-border-color-selected",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-swatch-size",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-animation-duration-100",


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-focus-indicator-color",


[markdownlint-fix] reported by reviewdog 🐶


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-gray-800",
"--spectrum-gray-900",


[markdownlint-fix] reported by reviewdog 🐶


[markdownlint-fix] reported by reviewdog 🐶

"--spectrum-workflow-icon-size-100",


[markdownlint-fix] reported by reviewdog 🐶

"--highcontrast-swatch-focus-indicator-color"


[markdownlint-fix] reported by reviewdog 🐶

".spectrum-SwatchGroup--spacious"


[markdownlint-fix] reported by reviewdog 🐶

"modifiers": [
"--mod-swatchgroup-spacing-compact",
"--mod-swatchgroup-spacing-regular",
"--mod-swatchgroup-spacing-spacious"


[markdownlint-fix] reported by reviewdog 🐶

"component": ["--spectrum-swatchgroup-spacing"],


[markdownlint-fix] reported by reviewdog 🐶

@saashapina saashapina self-assigned this May 19, 2025
@saashapina saashapina added size-1 XS ~1-6hrs; nearly trivial, a few hours, could do more than one in a single day. ready-for-review labels May 19, 2025
Copy link
Collaborator

@castastrophe castastrophe left a comment

Choose a reason for hiding this comment

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

I can see why we need the extra specificity but I'm not sure it will translate well when it gets to the web component (.spectrum-Switch.spectrum-Switch converted likely to :host:host). We can merge this in but would you mind adding some details about what selectors it's clashing with and why we added it?

"@spectrum-css/switch": patch
---

Fix active down state specificity
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you expound a little on this in a long format? We use this information to populate our Changelogs so we try to include as much as possible to help customers validate this update on their end.

@@ -229,7 +229,7 @@
border-color: var(--highcontrast-switch-border-color-hover, var(--mod-switch-border-color-hover, var(--spectrum-switch-border-color-hover)));
}

.spectrum-Switch:active & {
.spectrum-Switch.spectrum-Switch:active & {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a comment about the specificity this helps with? This won't likely translate to the web component (:host:host) so we want to document that issue if we can.

Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like what it will convert to - :host(:active):host(:active) - is accepted as a selector, and does bump specificity.

However, there is still a conflict when the switch is both checked and active:
image

Maybe we need to add a few more states to the testing grid for "Active + Unchecked" and "Active + Checked"

@saashapina saashapina force-pushed the saashapina/fix-switch-down-state branch from 5dff2ea to 52a70a4 Compare May 22, 2025 21:12
@saashapina saashapina requested a review from 5t3ph May 22, 2025 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-review size-1 XS ~1-6hrs; nearly trivial, a few hours, could do more than one in a single day.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants