storybook-addon-pseudo-states icon indicating copy to clipboard operation
storybook-addon-pseudo-states copied to clipboard

Wrapping `:where` ignored when substituting pseudo-class selector with `.pseudo-*-all` class selector

Open martyfmelb opened this issue 8 months ago • 0 comments
trafficstars

Using storybook 8.3.5 / storybook-addon-pseudo-states 4.0.2 (also an issue in 3.1.1).

Problem

Our typography system has this CSS (only relevant parts shown):

.textLink:where(:focus-visible) { /* specificity 0-1-0 -- tie */
  outline: 1px solid var(--my-focus-ring-color);
  text-decoration: none;
}

.textLink {                      /* specificity 0-1-0 -- tie -- but winner due to source order */
  text-decoration: underline;
}

The add-on turns it into:

.textLink:where(:focus-visible),               /* specificity 0-1-0 */
.textLink:where(.pseudo-focus-visible),        /* specificity 0-1-0 */
.pseudo-focus-visible-all .textLink:where(*) { /* BUG 🐞 specificity 0-2-0 -- winner due to higher specificity */
  outline: 1px solid var(--my-focus-ring-color);
  text-decoration: none;
}

.textLink {
  text-decoration: underline;                 /* specificity 0-1-0 */
}

Which changes the styles, but shouldn't.

Rather, it should output:

.textLink:where(:focus-visible),              /* specificity 0-1-0 -- tie */
.textLink:where(.pseudo-focus-visible),       /* specificity 0-1-0 -- tie */
:where(.pseudo-focus-visible-all) .textLink { /* FIX 🛠️ specificity 0-1-0 -- tie */
  outline: 1px solid var(--my-focus-ring-color);
  text-decoration: none;
}

.textLink {
  text-decoration: underline;                 /* specificity 0-1-0 -- tie -- but winner due to source order */
}

Which doesn't change the resultant style.

Possibly relates to #125 .

martyfmelb avatar Mar 17 '25 00:03 martyfmelb