From 12cbce036a0fa0a163cb2b6ddb654edb07c63c72 Mon Sep 17 00:00:00 2001
From: gndz07 <70909035+gndz07@users.noreply.github.com>
Date: Thu, 26 Nov 2026 10:15:59 +0100
Subject: [PATCH 1/7] fix: use stateLayer for accordion, badge, list, select
---
BREAKING_CHANGES.md | 35 +++++++++++++++++++
components/Accordion/Accordion.vanilla.css.ts | 12 ++-----
components/Badge/Badge.theme.ts | 8 ++---
components/Badge/Badge.vanilla.css.ts | 16 +++------
components/List/List.vanilla.css.ts | 26 +++-----------
components/Select/Select.vanilla.css.ts | 20 ++---------
styles/stateLayers.ts | 3 ++
styles/themes.css.ts | 14 ++++++++
styles/tokens.css.ts | 1 +
9 files changed, 70 insertions(+), 65 deletions(-)
create mode 100644 styles/stateLayers.ts
diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md
index 994bc83d..7fc050bf 100644
--- a/BREAKING_CHANGES.md
+++ b/BREAKING_CHANGES.md
@@ -260,6 +260,7 @@ The same applies to `Li`, which takes the Flex layout props.
- **Panel** no longer has a box shadow (Dropdown and Popover set their own elevation, so they are unaffected)
- **Badge** `alphaBg` uses the `A3` color step instead of `A6`
+- **Badge** interactive hover and active backgrounds are stronger (8% and 15% instead of 5% and 10%), and lighten instead of darken in dark mode
- **Alert** `gray` variant ring uses `gray9` (the neutral tone) instead of `slate9`
---
@@ -532,6 +533,34 @@ globalStyle(`${monoInput} input`, { fontFamily: 'monospace' });
---
+### State Backgrounds: Layers Instead of Pseudo-Elements
+
+**Change:** Hover and active backgrounds are drawn as `background-image` layers on the element itself, over its `background-color`, instead of on `::before` and `::after`.
+
+**Affected:** `AccordionTrigger`, interactive `Badge`, interactive `Li`, `SelectTrigger`
+
+| | Before | After |
+| ----------------------- | ----------------------------------------------- | ------------------------------------------- |
+| Hover and active colors | `::before`, plus a 5% primary tint on `::after` | `background-image` layers on the element |
+| Primary tint | `primary` at `opacity: 0.05` | the `primaryTint` theme token |
+| Text over the state | covered by the semi-transparent layer | drawn above the background, unchanged color |
+
+**Migration Guide:**
+
+1. Move overrides that target `::before` or `::after` of these components to the element itself
+2. Change the base color with `background-color`, through `css` or `className`: the state layers stay on top of it. Avoid the `background` shorthand in `css`, which would remove them
+3. Change a state color with a `className` that sets `background-image` on `:hover` or `:active`, since `css` cannot target states
+
+**Rationale:**
+
+- A custom base color keeps the hover and active states
+- Overriding a state is one rule on the element, not on an internal pseudo-element
+- Frees `::before` and `::after` for consumers
+
+**Impact:** Low - Visual only, unless an app styles these pseudo-elements
+
+---
+
## Components Supporting Polymorphic `as` Prop
### Layout Components
@@ -886,6 +915,12 @@ Release notes are generated by semantic-release; use this as the body of the bre
- **Removed:** `elevation` on `NavigationMenuTrigger`, which had no effect
- See [Migration Guide](./BREAKING_CHANGES.md#navigationmenu-as-on-every-part-and-scoped-list-styles)
+#### State Backgrounds
+
+- **Changed:** `AccordionTrigger`, interactive `Badge`, interactive `Li` and `SelectTrigger` draw hover and active backgrounds as `background-image` layers instead of `::before`/`::after`
+ - Migration: move pseudo-element overrides to the element itself
+ - See [Migration Guide](./BREAKING_CHANGES.md#state-backgrounds-layers-instead-of-pseudo-elements)
+
#### Theme Provider
- **Changed:** Requires `VanillaExtractThemeProvider` at the app root
diff --git a/components/Accordion/Accordion.vanilla.css.ts b/components/Accordion/Accordion.vanilla.css.ts
index 93c819d2..ee298d15 100644
--- a/components/Accordion/Accordion.vanilla.css.ts
+++ b/components/Accordion/Accordion.vanilla.css.ts
@@ -1,6 +1,7 @@
import { keyframes, style } from '@vanilla-extract/css';
import { recipe } from '@vanilla-extract/recipes';
+import { stateLayers } from '@/styles/stateLayers';
import { tokens } from '@/styles/tokens.css';
import { elevationVariants } from '@/components/Elevation/Elevation.vanilla.css';
@@ -82,13 +83,6 @@ export const accordionTriggerRecipe = recipe({
transition: 'opacity 200ms ease-out',
selectors: {
- '&::before': {
- borderRadius: 'inherit',
- boxSizing: 'border-box',
- content: '""',
- position: 'absolute',
- inset: 0,
- },
'&:focus': {
boxShadow: `inset 0 0 0 1px ${tokens.colors.accordionActiveShadow}`,
},
@@ -99,9 +93,7 @@ export const accordionTriggerRecipe = recipe({
selectors: {
'&:not([disabled]):hover': {
cursor: 'pointer',
- },
- '&:not([disabled]):hover::before': {
- backgroundColor: tokens.colors.accordionHoverShadow,
+ backgroundImage: stateLayers(tokens.colors.accordionHoverShadow),
},
},
},
diff --git a/components/Badge/Badge.theme.ts b/components/Badge/Badge.theme.ts
index 419380e2..23fa672e 100644
--- a/components/Badge/Badge.theme.ts
+++ b/components/Badge/Badge.theme.ts
@@ -1,11 +1,11 @@
// Plain TypeScript color tokens (no vanilla-extract)
// Can be safely imported by colors/index.ts for Stitches
export const badgeLightTheme = {
- badgeInteractiveBackgroundHover: 'hsla(0, 0%, 0%, 0.05)',
- badgeInteractiveBackgroundActive: 'hsla(0, 0%, 0%, 0.1)',
+ badgeInteractiveBackgroundHover: 'hsla(0, 0%, 0%, 0.08)',
+ badgeInteractiveBackgroundActive: 'hsla(0, 0%, 0%, 0.15)',
};
export const badgeDarkTheme = {
- badgeInteractiveBackgroundHover: 'hsla(0, 0%, 0%, 0.1)',
- badgeInteractiveBackgroundActive: 'hsla(0, 0%, 0%, 0.2)',
+ badgeInteractiveBackgroundHover: 'hsla(0, 0%, 100%, 0.08)',
+ badgeInteractiveBackgroundActive: 'hsla(0, 0%, 100%, 0.15)',
};
diff --git a/components/Badge/Badge.vanilla.css.ts b/components/Badge/Badge.vanilla.css.ts
index ab4e308c..c92008d0 100644
--- a/components/Badge/Badge.vanilla.css.ts
+++ b/components/Badge/Badge.vanilla.css.ts
@@ -1,6 +1,7 @@
import { style } from '@vanilla-extract/css';
import { recipe } from '@vanilla-extract/recipes';
+import { stateLayers } from '@/styles/stateLayers';
import { tokens } from '@/styles/tokens.css';
const baseBadge = style({
@@ -38,24 +39,15 @@ const interactiveBadge = style([
baseBadge,
{
selectors: {
- '&::before': {
- boxSizing: 'border-box',
- content: '""',
- position: 'absolute',
- inset: 0,
- borderRadius: 'inherit',
- },
'&:focus-visible': {
outline: `2px solid ${tokens.colors.primary}`,
},
'&:hover': {
cursor: 'pointer',
+ backgroundImage: stateLayers(tokens.colors.badgeInteractiveBackgroundHover),
},
- '&:hover::before': {
- backgroundColor: tokens.colors.badgeInteractiveBackgroundHover,
- },
- '&:active::before': {
- backgroundColor: tokens.colors.badgeInteractiveBackgroundActive,
+ '&:active': {
+ backgroundImage: stateLayers(tokens.colors.badgeInteractiveBackgroundActive),
},
},
},
diff --git a/components/List/List.vanilla.css.ts b/components/List/List.vanilla.css.ts
index bdde1462..45bf0a3e 100644
--- a/components/List/List.vanilla.css.ts
+++ b/components/List/List.vanilla.css.ts
@@ -1,6 +1,7 @@
import { globalStyle, style } from '@vanilla-extract/css';
import { recipe } from '@vanilla-extract/recipes';
+import { stateLayers } from '@/styles/stateLayers';
import { tokens } from '@/styles/tokens.css';
import { elevationVariants } from '@/components/Elevation/Elevation.vanilla.css';
@@ -77,19 +78,6 @@ export const itemText = style([
},
]);
-const itemLayer = {
- borderRadius: 'inherit',
- boxSizing: 'border-box',
- content: '""',
- position: 'absolute',
- inset: 0,
-} as const;
-
-const primaryTint = {
- backgroundColor: tokens.colors.primary,
- opacity: 0.05,
-};
-
export const itemButton = style([
itemContent,
{
@@ -107,8 +95,6 @@ export const itemButton = style([
position: 'relative',
selectors: {
- '&::before': itemLayer,
- '&::after': itemLayer,
// No pointer-events: none, or clicks would fall through to the
and fire its onClick.
'&:disabled': {
opacity: 0.5,
@@ -116,10 +102,9 @@ export const itemButton = style([
'&:focus, &:focus-visible': {
boxShadow: `inset 0 0 0 2px ${tokens.colors.listItemFocusBorder}`,
},
- '&:enabled:active::before': {
- backgroundColor: tokens.colors.listItemActiveBg,
+ '&:enabled:active': {
+ backgroundImage: stateLayers(tokens.colors.primaryTint, tokens.colors.listItemActiveBg),
},
- '&:enabled:active::after': primaryTint,
},
'@media': {
@@ -127,11 +112,8 @@ export const itemButton = style([
selectors: {
'&:enabled:hover': {
cursor: 'pointer',
+ backgroundImage: stateLayers(tokens.colors.primaryTint, tokens.colors.listItemHoverBg),
},
- '&:enabled:hover::before': {
- backgroundColor: tokens.colors.listItemHoverBg,
- },
- '&:enabled:hover::after': primaryTint,
},
},
},
diff --git a/components/Select/Select.vanilla.css.ts b/components/Select/Select.vanilla.css.ts
index d88a42bb..64f60cc1 100644
--- a/components/Select/Select.vanilla.css.ts
+++ b/components/Select/Select.vanilla.css.ts
@@ -2,21 +2,13 @@ import { style } from '@vanilla-extract/css';
import { recipe } from '@vanilla-extract/recipes';
import { breakpoints } from '@/styles/breakpoints.css';
+import { stateLayers } from '@/styles/stateLayers';
import { tokens } from '@/styles/tokens.css';
const FOCUS_SHADOW =
'0 1px 5px 0 hsla(0, 0%, 0%, 0.2), 0 3px 1px -2px hsla(0, 0%, 0%, 0.12), 0 2px 2px 0 hsla(0, 0%, 0%, 0.14)';
const CARET_WIDTH = '15px';
-const triggerLayer = {
- boxSizing: 'border-box',
- content: '""',
- position: 'absolute',
- inset: 0,
- pointerEvents: 'none',
- borderRadius: 'inherit',
-} as const;
-
const triggerSize = (height: string, radius: string, fontSize: string, space: string) => ({
height,
borderRadius: radius,
@@ -49,8 +41,6 @@ export const selectTriggerRecipe = recipe({
cursor: 'default',
selectors: {
- '&::before': triggerLayer,
- '&::after': triggerLayer,
'&[data-placeholder]': {
color: tokens.colors.selectPlaceholder,
},
@@ -67,12 +57,8 @@ export const selectTriggerRecipe = recipe({
'@media': {
[breakpoints.hover]: {
selectors: {
- '&:hover::before': {
- backgroundColor: tokens.colors.selectHoverBg,
- },
- '&:hover::after': {
- backgroundColor: tokens.colors.primary,
- opacity: 0.05,
+ '&:hover': {
+ backgroundImage: stateLayers(tokens.colors.primaryTint, tokens.colors.selectHoverBg),
},
},
},
diff --git a/styles/stateLayers.ts b/styles/stateLayers.ts
new file mode 100644
index 00000000..c0e72f00
--- /dev/null
+++ b/styles/stateLayers.ts
@@ -0,0 +1,3 @@
+// State colors go in `background-image`, over `background-color`, so a custom base color keeps them; the first color is on top.
+export const stateLayers = (...colors: string[]) =>
+ colors.map((color) => `linear-gradient(${color}, ${color})`).join(', ');
diff --git a/styles/themes.css.ts b/styles/themes.css.ts
index 0d1766fe..0fbc5514 100644
--- a/styles/themes.css.ts
+++ b/styles/themes.css.ts
@@ -444,6 +444,7 @@ const lightSemanticColors = {
export const lightThemeBlue = createTheme(tokens, {
colors: {
primary: lightColors.blue9, // Set primary to the actual color value
+ primaryTint: tinycolor(lightColors.blue9).setAlpha(0.05).toHslString(),
...lightSemanticColors,
...getButtonLightColors('blue'),
...getButtonSwitchLightColors('blue'),
@@ -464,6 +465,7 @@ export const lightThemeBlue = createTheme(tokens, {
export const lightThemeNeon = createTheme(tokens, {
colors: {
primary: lightColors.neon9, // Set primary to the actual color value
+ primaryTint: tinycolor(lightColors.neon9).setAlpha(0.05).toHslString(),
...lightSemanticColors,
...getButtonLightColors('neon'),
...getButtonSwitchLightColors('neon'),
@@ -484,6 +486,7 @@ export const lightThemeNeon = createTheme(tokens, {
export const lightThemeOrange = createTheme(tokens, {
colors: {
primary: lightColors.orange9, // Set primary to the actual color value
+ primaryTint: tinycolor(lightColors.orange9).setAlpha(0.05).toHslString(),
...lightSemanticColors,
...getButtonLightColors('orange'),
...getButtonSwitchLightColors('orange'),
@@ -504,6 +507,7 @@ export const lightThemeOrange = createTheme(tokens, {
export const lightThemeRed = createTheme(tokens, {
colors: {
primary: lightColors.red9, // Set primary to the actual color value
+ primaryTint: tinycolor(lightColors.red9).setAlpha(0.05).toHslString(),
...lightSemanticColors,
...getButtonLightColors('red'),
...getButtonSwitchLightColors('red'),
@@ -524,6 +528,7 @@ export const lightThemeRed = createTheme(tokens, {
export const lightThemeGreen = createTheme(tokens, {
colors: {
primary: lightColors.green9, // Set primary to the actual color value
+ primaryTint: tinycolor(lightColors.green9).setAlpha(0.05).toHslString(),
...lightSemanticColors,
...getButtonLightColors('green'),
...getButtonSwitchLightColors('green'),
@@ -544,6 +549,7 @@ export const lightThemeGreen = createTheme(tokens, {
export const lightThemeDeepBlue = createTheme(tokens, {
colors: {
primary: lightColors.deepBlue9, // Set primary to the actual color value
+ primaryTint: tinycolor(lightColors.deepBlue9).setAlpha(0.05).toHslString(),
...lightSemanticColors,
...getButtonLightColors('deepBlue'),
...getButtonSwitchLightColors('deepBlue'),
@@ -564,6 +570,7 @@ export const lightThemeDeepBlue = createTheme(tokens, {
export const lightThemeGrayBlue = createTheme(tokens, {
colors: {
primary: lightColors.grayBlue9, // Set primary to the actual color value
+ primaryTint: tinycolor(lightColors.grayBlue9).setAlpha(0.05).toHslString(),
...lightSemanticColors,
...getButtonLightColors('grayBlue'),
...getButtonSwitchLightColors('grayBlue'),
@@ -660,6 +667,7 @@ const darkSemanticColors = {
export const darkThemeBlue = createTheme(tokens, {
colors: {
primary: darkColors.blue9, // Set primary to the actual color value
+ primaryTint: tinycolor(darkColors.blue9).setAlpha(0.05).toHslString(),
...darkSemanticColors,
...getButtonDarkColors('blue'),
...getButtonSwitchDarkColors('blue'),
@@ -680,6 +688,7 @@ export const darkThemeBlue = createTheme(tokens, {
export const darkThemeNeon = createTheme(tokens, {
colors: {
primary: darkColors.neon9, // Set primary to the actual color value
+ primaryTint: tinycolor(darkColors.neon9).setAlpha(0.05).toHslString(),
...darkSemanticColors,
...getButtonDarkColors('neon'),
...getButtonSwitchDarkColors('neon'),
@@ -700,6 +709,7 @@ export const darkThemeNeon = createTheme(tokens, {
export const darkThemeOrange = createTheme(tokens, {
colors: {
primary: darkColors.orange9, // Set primary to the actual color value
+ primaryTint: tinycolor(darkColors.orange9).setAlpha(0.05).toHslString(),
...darkSemanticColors,
...getButtonDarkColors('orange'),
...getButtonSwitchDarkColors('orange'),
@@ -720,6 +730,7 @@ export const darkThemeOrange = createTheme(tokens, {
export const darkThemeRed = createTheme(tokens, {
colors: {
primary: darkColors.red9, // Set primary to the actual color value
+ primaryTint: tinycolor(darkColors.red9).setAlpha(0.05).toHslString(),
...darkSemanticColors,
...getButtonDarkColors('red'),
...getButtonSwitchDarkColors('red'),
@@ -740,6 +751,7 @@ export const darkThemeRed = createTheme(tokens, {
export const darkThemeGreen = createTheme(tokens, {
colors: {
primary: darkColors.green9, // Set primary to the actual color value
+ primaryTint: tinycolor(darkColors.green9).setAlpha(0.05).toHslString(),
...darkSemanticColors,
...getButtonDarkColors('green'),
...getButtonSwitchDarkColors('green'),
@@ -760,6 +772,7 @@ export const darkThemeGreen = createTheme(tokens, {
export const darkThemeDeepBlue = createTheme(tokens, {
colors: {
primary: darkColors.deepBlue9, // Set primary to the actual color value
+ primaryTint: tinycolor(darkColors.deepBlue9).setAlpha(0.05).toHslString(),
...darkSemanticColors,
...getButtonDarkColors('deepBlue'),
...getButtonSwitchDarkColors('deepBlue'),
@@ -780,6 +793,7 @@ export const darkThemeDeepBlue = createTheme(tokens, {
export const darkThemeGrayBlue = createTheme(tokens, {
colors: {
primary: darkColors.grayBlue9, // Set primary to the actual color value
+ primaryTint: tinycolor(darkColors.grayBlue9).setAlpha(0.05).toHslString(),
...darkSemanticColors,
...getButtonDarkColors('grayBlue'),
...getButtonSwitchDarkColors('grayBlue'),
diff --git a/styles/tokens.css.ts b/styles/tokens.css.ts
index e9cde115..6d849cf3 100644
--- a/styles/tokens.css.ts
+++ b/styles/tokens.css.ts
@@ -35,6 +35,7 @@ export const tokens = createThemeContract({
colors: {
// Semantic colors
primary: null,
+ primaryTint: null,
contentBg: null,
hiContrast: null,
loContrast: null,
From 80f5fc588ae15ee2960e46b2abf400a33dafe276 Mon Sep 17 00:00:00 2001
From: gndz07 <70909035+gndz07@users.noreply.github.com>
Date: Thu, 26 Nov 2026 10:27:04 +0100
Subject: [PATCH 2/7] fix: use stateLayer for input, textarea, datetimepicker
---
BREAKING_CHANGES.md | 18 +++--
.../DateTimePickerInput.vanilla.css.ts | 32 +-------
components/Input/Input.theme.ts | 2 +
components/Input/Input.vanilla.css.ts | 75 +++++--------------
components/Textarea/Textarea.theme.ts | 2 +
components/Textarea/Textarea.vanilla.css.ts | 70 +++++------------
styles/tokens.css.ts | 2 +
7 files changed, 55 insertions(+), 146 deletions(-)
diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md
index 7fc050bf..3f1fd4c3 100644
--- a/BREAKING_CHANGES.md
+++ b/BREAKING_CHANGES.md
@@ -537,13 +537,17 @@ globalStyle(`${monoInput} input`, { fontFamily: 'monospace' });
**Change:** Hover and active backgrounds are drawn as `background-image` layers on the element itself, over its `background-color`, instead of on `::before` and `::after`.
-**Affected:** `AccordionTrigger`, interactive `Badge`, interactive `Li`, `SelectTrigger`
+**Affected:** `AccordionTrigger`, interactive `Badge`, interactive `Li`, `SelectTrigger`, the wrapper of `Input` and `Textarea` (and so `TextField` and `DateTimePickerInput`)
-| | Before | After |
-| ----------------------- | ----------------------------------------------- | ------------------------------------------- |
-| Hover and active colors | `::before`, plus a 5% primary tint on `::after` | `background-image` layers on the element |
-| Primary tint | `primary` at `opacity: 0.05` | the `primaryTint` theme token |
-| Text over the state | covered by the semi-transparent layer | drawn above the background, unchanged color |
+| | Before | After |
+| ----------------------- | ----------------------------------------------- | ----------------------------------------------------------------------- |
+| Hover and active colors | `::before`, plus a 5% primary tint on `::after` | `background-image` layers on the element |
+| Primary tint | `primary` at `opacity: 0.05` | the `primaryTint` theme token |
+| Invalid hover tint | `inputInvalidBorder` at `opacity: 0.05` | the `inputInvalidHoverTint` and `textareaInvalidHoverTint` theme tokens |
+| Text over the state | covered by the semi-transparent layer | drawn above the background, unchanged color |
+| Disabled invalid field | red hover tint | no hover, like any disabled field |
+
+The `Input` and `Textarea` wrappers also lose a `:focus-visible` background that never showed, since the wrapper cannot take focus.
**Migration Guide:**
@@ -917,7 +921,7 @@ Release notes are generated by semantic-release; use this as the body of the bre
#### State Backgrounds
-- **Changed:** `AccordionTrigger`, interactive `Badge`, interactive `Li` and `SelectTrigger` draw hover and active backgrounds as `background-image` layers instead of `::before`/`::after`
+- **Changed:** `AccordionTrigger`, interactive `Badge`, interactive `Li`, `SelectTrigger` and the `Input` and `Textarea` wrappers draw hover and active backgrounds as `background-image` layers instead of `::before`/`::after`
- Migration: move pseudo-element overrides to the element itself
- See [Migration Guide](./BREAKING_CHANGES.md#state-backgrounds-layers-instead-of-pseudo-elements)
diff --git a/components/DateTimePickerInput/DateTimePickerInput.vanilla.css.ts b/components/DateTimePickerInput/DateTimePickerInput.vanilla.css.ts
index 25fe927c..01c19216 100644
--- a/components/DateTimePickerInput/DateTimePickerInput.vanilla.css.ts
+++ b/components/DateTimePickerInput/DateTimePickerInput.vanilla.css.ts
@@ -1,6 +1,7 @@
import { globalStyle, style } from '@vanilla-extract/css';
import { breakpoints } from '@/styles/breakpoints.css';
+import { stateLayers } from '@/styles/stateLayers';
import { tokens } from '@/styles/tokens.css';
export const wrapper = style({
@@ -23,14 +24,6 @@ globalStyle(`${input} input::-webkit-calendar-picker-indicator`, {
display: 'none',
});
-const pseudoLayer = {
- boxSizing: 'border-box',
- content: '""',
- position: 'absolute',
- inset: 0,
- pointerEvents: 'none',
-} as const;
-
// Firefox has no way to hide its native picker button, so cover it with a click target.
export const firefoxPatch = style({
display: 'none',
@@ -42,34 +35,17 @@ export const firefoxPatch = style({
position: 'absolute',
right: '17px',
top: '6px',
- background: tokens.colors.inputBg,
- selectors: {
- '&::before': pseudoLayer,
- '&::after': pseudoLayer,
- },
- },
- },
-});
-
-globalStyle(`${wrapper}:hover ${firefoxPatch}::before`, {
- '@supports': {
- '(-moz-appearance: none)': {
- '@media': {
- [breakpoints.hover]: {
- backgroundColor: tokens.colors.inputHoverBg,
- },
- },
+ backgroundColor: tokens.colors.inputBg,
},
},
});
-globalStyle(`${wrapper}:hover ${firefoxPatch}::after`, {
+globalStyle(`${wrapper}:hover ${firefoxPatch}`, {
'@supports': {
'(-moz-appearance: none)': {
'@media': {
[breakpoints.hover]: {
- backgroundColor: tokens.colors.primary,
- opacity: 0.05,
+ backgroundImage: stateLayers(tokens.colors.primaryTint, tokens.colors.inputHoverBg),
},
},
},
diff --git a/components/Input/Input.theme.ts b/components/Input/Input.theme.ts
index 1ee3c9c9..b94faedd 100644
--- a/components/Input/Input.theme.ts
+++ b/components/Input/Input.theme.ts
@@ -12,6 +12,7 @@ export const inputLightTheme = {
inputPlaceholder: 'hsla(0, 0%, 0%, 0.498)', // $blackA10
inputDisabledText: tinycolor('black').setAlpha(0.35).toHslString(),
inputInvalidBorder: 'hsl(358, 75%, 59%)', // $red9
+ inputInvalidHoverTint: tinycolor('hsl(358, 75%, 59%)').setAlpha(0.05).toHslString(),
};
export const inputDarkTheme = {
@@ -24,4 +25,5 @@ export const inputDarkTheme = {
inputPlaceholder: 'hsla(0, 0%, 100%, 0.455)', // $whiteA10
inputDisabledText: tinycolor('white').setAlpha(0.35).toHslString(),
inputInvalidBorder: 'hsl(358, 75%, 59%)', // $red9
+ inputInvalidHoverTint: tinycolor('hsl(358, 75%, 59%)').setAlpha(0.05).toHslString(),
};
diff --git a/components/Input/Input.vanilla.css.ts b/components/Input/Input.vanilla.css.ts
index 27501107..1a8f65b0 100644
--- a/components/Input/Input.vanilla.css.ts
+++ b/components/Input/Input.vanilla.css.ts
@@ -2,6 +2,7 @@ import { style } from '@vanilla-extract/css';
import { recipe } from '@vanilla-extract/recipes';
import { breakpoints } from '@/styles/breakpoints.css';
+import { stateLayers } from '@/styles/stateLayers';
import { tokens } from '@/styles/tokens.css';
// CONSTANTS
@@ -278,39 +279,11 @@ const inputWrapperBase = style({
backgroundColor: tokens.colors.inputBg,
color: tokens.colors.inputPlaceholder,
- selectors: {
- '&::before': {
- boxSizing: 'border-box',
- content: '""',
- position: 'absolute',
- inset: '0',
- pointerEvents: 'none',
- },
- '&::after': {
- boxSizing: 'border-box',
- content: '""',
- position: 'absolute',
- inset: '0',
- pointerEvents: 'none',
- },
- '&:focus-visible::before': {
- backgroundColor: tokens.colors.inputFocusBg,
- },
- '&:focus-visible::after': {
- backgroundColor: tokens.colors.primary,
- opacity: '0.15',
- },
- },
-
'@media': {
[breakpoints.hover]: {
selectors: {
- '&:hover::before': {
- backgroundColor: tokens.colors.inputHoverBg,
- },
- '&:hover::after': {
- backgroundColor: tokens.colors.primary,
- opacity: '0.05',
+ '&:hover': {
+ backgroundImage: stateLayers(tokens.colors.primaryTint, tokens.colors.inputHoverBg),
},
},
},
@@ -320,31 +293,32 @@ const inputWrapperBase = style({
export const inputWrapperRecipe = recipe({
base: inputWrapperBase,
variants: {
- disabled: {
- true: {
- opacity: '0.7',
- color: tokens.colors.inputDisabledText,
+ state: {
+ invalid: {
'@media': {
[breakpoints.hover]: {
selectors: {
- '&:hover::before': {
- backgroundColor: 'inherit',
- },
- '&:hover::after': {
- backgroundColor: 'inherit',
+ '&:hover': {
+ backgroundImage: stateLayers(
+ tokens.colors.inputInvalidHoverTint,
+ tokens.colors.inputHoverBg,
+ ),
},
},
},
},
},
},
- state: {
- invalid: {
+ // After `state`, so a disabled invalid input has no hover either.
+ disabled: {
+ true: {
+ opacity: '0.7',
+ color: tokens.colors.inputDisabledText,
'@media': {
[breakpoints.hover]: {
selectors: {
- '&:hover::after': {
- backgroundColor: tokens.colors.inputInvalidBorder,
+ '&:hover': {
+ backgroundImage: 'none',
},
},
},
@@ -354,27 +328,12 @@ export const inputWrapperRecipe = recipe({
size: {
small: {
borderRadius: tokens.radii['2'],
- selectors: {
- '&::before, &::after': {
- borderRadius: tokens.radii['2'],
- },
- },
},
medium: {
borderRadius: tokens.radii['3'],
- selectors: {
- '&::before, &::after': {
- borderRadius: tokens.radii['3'],
- },
- },
},
large: {
borderRadius: tokens.radii['3'],
- selectors: {
- '&::before, &::after': {
- borderRadius: tokens.radii['3'],
- },
- },
},
},
},
diff --git a/components/Textarea/Textarea.theme.ts b/components/Textarea/Textarea.theme.ts
index 915180aa..e55b4fe1 100644
--- a/components/Textarea/Textarea.theme.ts
+++ b/components/Textarea/Textarea.theme.ts
@@ -12,6 +12,7 @@ export const textareaLightTheme = {
textareaPlaceholder: 'hsla(0, 0%, 0%, 0.498)', // $blackA10
textareaDisabledText: tinycolor('black').setAlpha(0.35).toHslString(),
textareaInvalidBorder: 'hsl(358, 75%, 59%)', // $red9
+ textareaInvalidHoverTint: tinycolor('hsl(358, 75%, 59%)').setAlpha(0.05).toHslString(),
};
export const textareaDarkTheme = {
@@ -24,4 +25,5 @@ export const textareaDarkTheme = {
textareaPlaceholder: 'hsla(0, 0%, 100%, 0.455)', // $whiteA10
textareaDisabledText: tinycolor('white').setAlpha(0.35).toHslString(),
textareaInvalidBorder: 'hsl(358, 75%, 59%)', // $red9
+ textareaInvalidHoverTint: tinycolor('hsl(358, 75%, 59%)').setAlpha(0.05).toHslString(),
};
diff --git a/components/Textarea/Textarea.vanilla.css.ts b/components/Textarea/Textarea.vanilla.css.ts
index d4239dd8..64601f47 100644
--- a/components/Textarea/Textarea.vanilla.css.ts
+++ b/components/Textarea/Textarea.vanilla.css.ts
@@ -2,6 +2,7 @@ import { style } from '@vanilla-extract/css';
import { recipe } from '@vanilla-extract/recipes';
import { breakpoints } from '@/styles/breakpoints.css';
+import { stateLayers } from '@/styles/stateLayers';
import { tokens } from '@/styles/tokens.css';
// CONSTANTS
@@ -90,15 +91,6 @@ export const styledTextareaRecipe = recipe({
boxShadow: `inset 0 0 0 2px ${tokens.colors.textareaInvalidBorder}, inset 0 0 0 100px ${tokens.colors.textareaBg}, ${FOCUS_SHADOW}`,
},
},
- '@media': {
- [breakpoints.hover]: {
- selectors: {
- '&:hover::after': {
- backgroundColor: tokens.colors.textareaInvalidBorder,
- },
- },
- },
- },
},
},
cursor: {
@@ -172,40 +164,11 @@ const textareaWrapperBase = style({
color: tokens.colors.textareaPlaceholder,
borderRadius: tokens.radii['3'],
- selectors: {
- '&::before': {
- boxSizing: 'border-box',
- borderRadius: 'inherit',
- content: '""',
- position: 'absolute',
- inset: '0',
- pointerEvents: 'none',
- },
- '&::after': {
- boxSizing: 'border-box',
- borderRadius: 'inherit',
- content: '""',
- position: 'absolute',
- inset: '0',
- pointerEvents: 'none',
- },
- '&:focus-visible::before': {
- backgroundColor: tokens.colors.textareaFocusBg,
- },
- '&:focus-visible::after': {
- backgroundColor: tokens.colors.primary,
- opacity: '0.15',
- },
- },
'@media': {
[breakpoints.hover]: {
selectors: {
- '&:hover::before': {
- backgroundColor: tokens.colors.textareaHoverBg,
- },
- '&:hover::after': {
- backgroundColor: tokens.colors.primary,
- opacity: '0.05',
+ '&:hover': {
+ backgroundImage: stateLayers(tokens.colors.primaryTint, tokens.colors.textareaHoverBg),
},
},
},
@@ -215,31 +178,32 @@ const textareaWrapperBase = style({
export const textareaWrapperRecipe = recipe({
base: textareaWrapperBase,
variants: {
- disabled: {
- true: {
- opacity: '0.7',
- color: tokens.colors.textareaDisabledText,
+ state: {
+ invalid: {
'@media': {
[breakpoints.hover]: {
selectors: {
- '&:hover::before': {
- backgroundColor: 'inherit',
- },
- '&:hover::after': {
- backgroundColor: 'inherit',
+ '&:hover': {
+ backgroundImage: stateLayers(
+ tokens.colors.textareaInvalidHoverTint,
+ tokens.colors.textareaHoverBg,
+ ),
},
},
},
},
},
},
- state: {
- invalid: {
+ // After `state`, so a disabled invalid textarea has no hover either.
+ disabled: {
+ true: {
+ opacity: '0.7',
+ color: tokens.colors.textareaDisabledText,
'@media': {
[breakpoints.hover]: {
selectors: {
- '&:hover::after': {
- backgroundColor: tokens.colors.textareaInvalidBorder,
+ '&:hover': {
+ backgroundImage: 'none',
},
},
},
diff --git a/styles/tokens.css.ts b/styles/tokens.css.ts
index 6d849cf3..01d82112 100644
--- a/styles/tokens.css.ts
+++ b/styles/tokens.css.ts
@@ -120,6 +120,7 @@ export const tokens = createThemeContract({
inputPlaceholder: null,
inputDisabledText: null,
inputInvalidBorder: null,
+ inputInvalidHoverTint: null,
selectBg: null,
selectBorder: null,
@@ -139,6 +140,7 @@ export const tokens = createThemeContract({
textareaPlaceholder: null,
textareaDisabledText: null,
textareaInvalidBorder: null,
+ textareaInvalidHoverTint: null,
buttonPrimaryText: null,
buttonPrimaryFocusBorder: null,
From 5b08628ad53fb198367884abbfa094d493ed2d08 Mon Sep 17 00:00:00 2001
From: gndz07 <70909035+gndz07@users.noreply.github.com>
Date: Thu, 26 Nov 2026 10:33:48 +0100
Subject: [PATCH 3/7] fix: use stateLayer for card & alert
---
BREAKING_CHANGES.md | 8 ++-
components/Alert/Alert.vanilla.css.ts | 7 ++-
components/Card/Card.vanilla.css.ts | 70 ++++++++++-----------------
3 files changed, 34 insertions(+), 51 deletions(-)
diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md
index 3f1fd4c3..293a4c21 100644
--- a/BREAKING_CHANGES.md
+++ b/BREAKING_CHANGES.md
@@ -537,7 +537,7 @@ globalStyle(`${monoInput} input`, { fontFamily: 'monospace' });
**Change:** Hover and active backgrounds are drawn as `background-image` layers on the element itself, over its `background-color`, instead of on `::before` and `::after`.
-**Affected:** `AccordionTrigger`, interactive `Badge`, interactive `Li`, `SelectTrigger`, the wrapper of `Input` and `Textarea` (and so `TextField` and `DateTimePickerInput`)
+**Affected:** `AccordionTrigger`, interactive `Badge`, `Card` (and so `Alert`), interactive `Li`, `SelectTrigger`, the wrapper of `Input` and `Textarea` (and so `TextField` and `DateTimePickerInput`)
| | Before | After |
| ----------------------- | ----------------------------------------------- | ----------------------------------------------------------------------- |
@@ -546,9 +546,13 @@ globalStyle(`${monoInput} input`, { fontFamily: 'monospace' });
| Invalid hover tint | `inputInvalidBorder` at `opacity: 0.05` | the `inputInvalidHoverTint` and `textareaInvalidHoverTint` theme tokens |
| Text over the state | covered by the semi-transparent layer | drawn above the background, unchanged color |
| Disabled invalid field | red hover tint | no hover, like any disabled field |
+| `Card` state outline | on `::before` | on the element |
+| `Alert` ring | inset `box-shadow` on `::before` | inset `box-shadow` on the element, before the elevation shadow |
The `Input` and `Textarea` wrappers also lose a `:focus-visible` background that never showed, since the wrapper cannot take focus.
+A `box-shadow` set on an `Alert` through `css` or `className` now replaces its ring too.
+
**Migration Guide:**
1. Move overrides that target `::before` or `::after` of these components to the element itself
@@ -921,7 +925,7 @@ Release notes are generated by semantic-release; use this as the body of the bre
#### State Backgrounds
-- **Changed:** `AccordionTrigger`, interactive `Badge`, interactive `Li`, `SelectTrigger` and the `Input` and `Textarea` wrappers draw hover and active backgrounds as `background-image` layers instead of `::before`/`::after`
+- **Changed:** `AccordionTrigger`, interactive `Badge`, `Card`, `Alert`, interactive `Li`, `SelectTrigger` and the `Input` and `Textarea` wrappers draw hover and active backgrounds as `background-image` layers instead of `::before`/`::after`; `Card` outlines and the `Alert` ring move to the element
- Migration: move pseudo-element overrides to the element itself
- See [Migration Guide](./BREAKING_CHANGES.md#state-backgrounds-layers-instead-of-pseudo-elements)
diff --git a/components/Alert/Alert.vanilla.css.ts b/components/Alert/Alert.vanilla.css.ts
index c90c4dd5..7f023e92 100644
--- a/components/Alert/Alert.vanilla.css.ts
+++ b/components/Alert/Alert.vanilla.css.ts
@@ -2,11 +2,10 @@ import { recipe } from '@vanilla-extract/recipes';
import { tokens } from '@/styles/tokens.css';
-// CardVanilla's `::before` overlay carries the ring, leaving the element's box-shadow to elevation.
+import { cardRing } from '@/components/Card/Card.vanilla.css';
+
const ring = (color: string) => ({
- '::before': {
- boxShadow: `inset 0 0 0 1px ${color}`,
- },
+ vars: { [cardRing]: `inset 0 0 0 1px ${color}` },
});
export const alertRecipe = recipe({
diff --git a/components/Card/Card.vanilla.css.ts b/components/Card/Card.vanilla.css.ts
index 690655a4..d7e3882d 100644
--- a/components/Card/Card.vanilla.css.ts
+++ b/components/Card/Card.vanilla.css.ts
@@ -1,42 +1,40 @@
-import { style } from '@vanilla-extract/css';
+import { createVar, fallbackVar, style } from '@vanilla-extract/css';
import { recipe } from '@vanilla-extract/recipes';
import { breakpoints } from '@/styles/breakpoints.css';
+import { stateLayers } from '@/styles/stateLayers';
import { tokens } from '@/styles/tokens.css';
-// Elevation variants matching Elevation component
+// Lets Alert add an inset ring without replacing the elevation shadow.
+export const cardRing = createVar();
+const ring = fallbackVar(cardRing, '0 0 #0000');
+
const elevationVariants = {
0: {
- boxShadow: 'none',
+ boxShadow: ring,
},
1: {
backgroundColor: tokens.colors['01dp'],
- boxShadow:
- '0 1px 5px 0 hsla(0, 0%, 0%, 0.2), 0 3px 1px -2px hsla(0, 0%, 0%, 0.12), 0 2px 2px 0 hsla(0, 0%, 0%, 0.14)',
+ boxShadow: `${ring}, 0 1px 5px 0 hsla(0, 0%, 0%, 0.2), 0 3px 1px -2px hsla(0, 0%, 0%, 0.12), 0 2px 2px 0 hsla(0, 0%, 0%, 0.14)`,
},
2: {
backgroundColor: tokens.colors['02dp'],
- boxShadow:
- '0 2px 4px -1px hsla(0, 0%, 0%, 0.2), 0 1px 10px 0 hsla(0, 0%, 0%, 0.12), 0 4px 5px 0 hsla(0, 0%, 0%, 0.14)',
+ boxShadow: `${ring}, 0 2px 4px -1px hsla(0, 0%, 0%, 0.2), 0 1px 10px 0 hsla(0, 0%, 0%, 0.12), 0 4px 5px 0 hsla(0, 0%, 0%, 0.14)`,
},
3: {
backgroundColor: tokens.colors['03dp'],
- boxShadow:
- '0 3px 5px -1px hsla(0, 0%, 0%, 0.2), 0 1px 18px 0 hsla(0, 0%, 0%, 0.12), 0 6px 10px 0 hsla(0, 0%, 0%, 0.14)',
+ boxShadow: `${ring}, 0 3px 5px -1px hsla(0, 0%, 0%, 0.2), 0 1px 18px 0 hsla(0, 0%, 0%, 0.12), 0 6px 10px 0 hsla(0, 0%, 0%, 0.14)`,
},
4: {
backgroundColor: tokens.colors['04dp'],
- boxShadow:
- '0 7px 8px -4px hsla(0, 0%, 0%, 0.2), 0 5px 22px 4px hsla(0, 0%, 0%, 0.12), 0 12px 17px 2px hsla(0, 0%, 0%, 0.14)',
+ boxShadow: `${ring}, 0 7px 8px -4px hsla(0, 0%, 0%, 0.2), 0 5px 22px 4px hsla(0, 0%, 0%, 0.12), 0 12px 17px 2px hsla(0, 0%, 0%, 0.14)`,
},
5: {
backgroundColor: tokens.colors['05dp'],
- boxShadow:
- '0 11px 15px -7px hsla(0, 0%, 0%, 0.2), 0 9px 46px 8px hsla(0, 0%, 0%, 0.12), 0 24px 38px 3px hsla(0, 0%, 0%, 0.14)',
+ boxShadow: `${ring}, 0 11px 15px -7px hsla(0, 0%, 0%, 0.2), 0 9px 46px 8px hsla(0, 0%, 0%, 0.12), 0 24px 38px 3px hsla(0, 0%, 0%, 0.14)`,
},
} as const;
-// Base card styles
const cardBase = style({
appearance: 'none',
border: 'none',
@@ -54,18 +52,6 @@ const cardBase = style({
color: 'inherit',
borderRadius: tokens.radii['3'],
position: 'relative',
-
- '::before': {
- boxSizing: 'border-box',
- content: '""',
- position: 'absolute',
- top: 0,
- right: 0,
- bottom: 0,
- left: 0,
- borderRadius: tokens.radii['3'],
- pointerEvents: 'none',
- },
});
export const cardRecipe = recipe({
@@ -79,15 +65,13 @@ export const cardRecipe = recipe({
},
ghost: {
backgroundColor: 'transparent',
- boxShadow: 'none',
+ boxShadow: ring,
},
},
active: {
true: {
- '::before': {
- outline: `1px solid ${tokens.colors.cardActiveBorder}`,
- backgroundColor: tokens.colors.cardActiveBackground,
- },
+ outline: `1px solid ${tokens.colors.cardActiveBorder}`,
+ backgroundImage: stateLayers(tokens.colors.cardActiveBackground),
},
},
},
@@ -97,7 +81,6 @@ export const cardRecipe = recipe({
},
});
-// Interactive card styles (for button element)
const interactiveCardBase = style([
cardBase,
{
@@ -106,21 +89,20 @@ const interactiveCardBase = style([
selectors: {
'&:hover': {
cursor: 'pointer',
- },
- '&:hover::before': {
outline: `1px solid ${tokens.colors.cardHoverBorder}`,
- backgroundColor: tokens.colors.cardHoverBackground,
+ backgroundImage: stateLayers(tokens.colors.cardHoverBackground),
},
},
},
},
selectors: {
- '&:focus': {
- outline: `2px solid ${tokens.colors.primary}`,
- },
- '&:active::before': {
+ '&:active': {
outline: `1px solid ${tokens.colors.cardActiveBorder}`,
- backgroundColor: tokens.colors.cardActiveBackground,
+ backgroundImage: stateLayers(tokens.colors.cardActiveBackground),
+ },
+ // Beats the hover and active outlines.
+ '&:focus, &:focus:hover, &:focus:active': {
+ outline: `2px solid ${tokens.colors.primary}`,
},
},
},
@@ -137,15 +119,13 @@ export const interactiveCardRecipe = recipe({
},
ghost: {
backgroundColor: 'transparent',
- boxShadow: 'none',
+ boxShadow: ring,
},
},
active: {
true: {
- '::before': {
- outline: `1px solid ${tokens.colors.cardActiveBorder}`,
- backgroundColor: tokens.colors.cardActiveBackground,
- },
+ outline: `1px solid ${tokens.colors.cardActiveBorder}`,
+ backgroundImage: stateLayers(tokens.colors.cardActiveBackground),
},
},
},
From d4aa2e8c95cfe4ad352cceb254259b374b3b0947 Mon Sep 17 00:00:00 2001
From: gndz07 <70909035+gndz07@users.noreply.github.com>
Date: Thu, 26 Nov 2026 10:51:36 +0100
Subject: [PATCH 4/7] fix: use stateLayer for buttons
---
BREAKING_CHANGES.md | 6 +-
components/Button/Button.vanilla.css.ts | 59 +++++--------------
.../ButtonSwitch/ButtonSwitch.vanilla.css.ts | 34 ++---------
components/Checkbox/Checkbox.vanilla.css.ts | 6 --
.../IconButton/IconButton.vanilla.css.ts | 38 +++---------
5 files changed, 34 insertions(+), 109 deletions(-)
diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md
index 293a4c21..2f07cd21 100644
--- a/BREAKING_CHANGES.md
+++ b/BREAKING_CHANGES.md
@@ -537,7 +537,7 @@ globalStyle(`${monoInput} input`, { fontFamily: 'monospace' });
**Change:** Hover and active backgrounds are drawn as `background-image` layers on the element itself, over its `background-color`, instead of on `::before` and `::after`.
-**Affected:** `AccordionTrigger`, interactive `Badge`, `Card` (and so `Alert`), interactive `Li`, `SelectTrigger`, the wrapper of `Input` and `Textarea` (and so `TextField` and `DateTimePickerInput`)
+**Affected:** `AccordionTrigger`, interactive `Badge`, `Button`, `ButtonSwitch`, `Card` (and so `Alert`), `IconButton`, interactive `Li`, `SelectTrigger`, the wrapper of `Input` and `Textarea` (and so `TextField` and `DateTimePickerInput`)
| | Before | After |
| ----------------------- | ----------------------------------------------- | ----------------------------------------------------------------------- |
@@ -553,6 +553,8 @@ The `Input` and `Textarea` wrappers also lose a `:focus-visible` background that
A `box-shadow` set on an `Alert` through `css` or `className` now replaces its ring too.
+`Button` still uses `::after` for the `waiting` stripes, which no longer fade while the button has keyboard focus.
+
**Migration Guide:**
1. Move overrides that target `::before` or `::after` of these components to the element itself
@@ -925,7 +927,7 @@ Release notes are generated by semantic-release; use this as the body of the bre
#### State Backgrounds
-- **Changed:** `AccordionTrigger`, interactive `Badge`, `Card`, `Alert`, interactive `Li`, `SelectTrigger` and the `Input` and `Textarea` wrappers draw hover and active backgrounds as `background-image` layers instead of `::before`/`::after`; `Card` outlines and the `Alert` ring move to the element
+- **Changed:** `AccordionTrigger`, interactive `Badge`, `Button`, `ButtonSwitch`, `Card`, `Alert`, `IconButton`, interactive `Li`, `SelectTrigger` and the `Input` and `Textarea` wrappers draw hover and active backgrounds as `background-image` layers instead of `::before`/`::after`; `Card` outlines and the `Alert` ring move to the element
- Migration: move pseudo-element overrides to the element itself
- See [Migration Guide](./BREAKING_CHANGES.md#state-backgrounds-layers-instead-of-pseudo-elements)
diff --git a/components/Button/Button.vanilla.css.ts b/components/Button/Button.vanilla.css.ts
index 6011c7ba..f335367c 100644
--- a/components/Button/Button.vanilla.css.ts
+++ b/components/Button/Button.vanilla.css.ts
@@ -1,16 +1,15 @@
import { keyframes, style } from '@vanilla-extract/css';
import { recipe, RecipeVariants } from '@vanilla-extract/recipes';
+import { stateLayers } from '@/styles/stateLayers';
import { tokens } from '@/styles/tokens.css';
-// Background size constants for waiting animation
const BG_SIZES = {
small: tokens.sizes['8'],
medium: tokens.sizes['9'],
large: tokens.sizes['10'],
};
-// Keyframe animation for waiting state
const backgroundSlide = keyframes({
'100%': { transform: `translateX(${tokens.sizes['9']})` },
});
@@ -23,7 +22,9 @@ const backgroundSlideLarge = keyframes({
'100%': { transform: `translateX(${tokens.sizes['10']})` },
});
-// Base button styles
+const HOVER_LAYER = 'rgba(255, 255, 255, 0.15)';
+const PRESSED_LAYER = 'rgba(0, 0, 0, 0.15)';
+
const baseButton = style({
// Reset
appearance: 'none',
@@ -46,35 +47,17 @@ const baseButton = style({
fontVariantNumeric: 'tabular-nums',
lineHeight: '1',
- // Pseudo-elements for hover/active effects
selectors: {
- '&::before': {
- boxSizing: 'border-box',
- content: '""',
- position: 'absolute',
- inset: 0,
- },
- '&::after': {
- boxSizing: 'border-box',
- content: '""',
- position: 'absolute',
- inset: 0,
- },
'&:disabled': {
pointerEvents: 'none',
opacity: 0.5,
},
'&:focus-visible': {
boxShadow: `inset 0 0 0 2px ${tokens.colors.focusOutline}`,
+ backgroundImage: stateLayers(HOVER_LAYER),
},
- '&:focus-visible::before': {
- backgroundColor: 'rgba(255, 255, 255, 0.15)',
- },
- '&:focus-visible::after': {
- opacity: 0.15,
- },
- '&:active::before': {
- backgroundColor: 'rgba(0, 0, 0, 0.15)',
+ '&:active': {
+ backgroundImage: stateLayers(PRESSED_LAYER),
},
},
@@ -83,12 +66,7 @@ const baseButton = style({
selectors: {
'&:hover': {
cursor: 'pointer',
- },
- '&:hover::before': {
- backgroundColor: 'rgba(255, 255, 255, 0.15)',
- },
- '&:hover::after': {
- opacity: 0.05,
+ backgroundImage: stateLayers(HOVER_LAYER),
},
},
},
@@ -137,8 +115,8 @@ export const buttonRecipe = recipe({
'@media': {
'(hover: hover)': {
selectors: {
- '&:hover::after': {
- backgroundColor: tokens.colors.primary,
+ '&:hover': {
+ backgroundImage: stateLayers(tokens.colors.primaryTint, HOVER_LAYER),
},
},
},
@@ -159,8 +137,8 @@ export const buttonRecipe = recipe({
'@media': {
'(hover: hover)': {
selectors: {
- '&:hover::after': {
- backgroundColor: tokens.colors.primary,
+ '&:hover': {
+ backgroundImage: stateLayers(tokens.colors.primaryTint, HOVER_LAYER),
},
},
},
@@ -194,6 +172,10 @@ export const buttonRecipe = recipe({
pointerEvents: 'none',
selectors: {
'&::after': {
+ content: '""',
+ position: 'absolute',
+ top: 0,
+ bottom: 0,
left: '-100%',
width: '200%',
backgroundSize: BG_SIZES.medium,
@@ -231,7 +213,6 @@ export const buttonRecipe = recipe({
},
compoundVariants: [
- // Primary + Ghost
{
variants: { variant: 'primary', ghost: true },
style: {
@@ -249,7 +230,6 @@ export const buttonRecipe = recipe({
},
},
},
- // Primary + Active
{
variants: { variant: 'primary', state: 'active' },
style: {
@@ -258,7 +238,6 @@ export const buttonRecipe = recipe({
boxShadow: 'inset 0 0 0 2px white',
},
},
- // Secondary + Waiting
{
variants: { variant: 'secondary', state: 'waiting' },
style: {
@@ -266,7 +245,6 @@ export const buttonRecipe = recipe({
color: 'transparent',
},
},
- // Secondary + Ghost
{
variants: { variant: 'secondary', ghost: true },
style: {
@@ -275,7 +253,6 @@ export const buttonRecipe = recipe({
boxShadow: 'none',
},
},
- // Red + Waiting
{
variants: { variant: 'red', state: 'waiting' },
style: {
@@ -283,7 +260,6 @@ export const buttonRecipe = recipe({
color: 'transparent',
},
},
- // Red + Active
{
variants: { variant: 'red', state: 'active' },
style: {
@@ -292,7 +268,6 @@ export const buttonRecipe = recipe({
boxShadow: 'inset 0 0 0 2px white',
},
},
- // Red + Ghost
{
variants: { variant: 'red', ghost: true },
style: {
@@ -310,7 +285,6 @@ export const buttonRecipe = recipe({
},
},
},
- // Small + Waiting (specific animation)
{
variants: { size: 'small', state: 'waiting' },
style: {
@@ -322,7 +296,6 @@ export const buttonRecipe = recipe({
},
},
},
- // Large + Waiting (specific animation)
{
variants: { size: 'large', state: 'waiting' },
style: {
diff --git a/components/ButtonSwitch/ButtonSwitch.vanilla.css.ts b/components/ButtonSwitch/ButtonSwitch.vanilla.css.ts
index c7326361..030e46b2 100644
--- a/components/ButtonSwitch/ButtonSwitch.vanilla.css.ts
+++ b/components/ButtonSwitch/ButtonSwitch.vanilla.css.ts
@@ -1,5 +1,6 @@
import { style } from '@vanilla-extract/css';
+import { stateLayers } from '@/styles/stateLayers';
import { tokens } from '@/styles/tokens.css';
export const buttonSwitchContainer = style({
@@ -10,6 +11,8 @@ export const buttonSwitchContainer = style({
gap: tokens.space['1'],
});
+const HOVER_LAYER = 'rgba(255, 255, 255, 0.15)';
+
export const buttonSwitchItem = style({
display: 'inline-flex',
backgroundColor: tokens.colors.buttonSwitchOffBg,
@@ -19,36 +22,16 @@ export const buttonSwitchItem = style({
justifyContent: 'center',
fontWeight: 600,
border: 'none',
+ borderRadius: tokens.radii['3'],
position: 'relative',
selectors: {
- '&::before': {
- boxSizing: 'border-box',
- content: '""',
- position: 'absolute',
- inset: 0,
- borderRadius: tokens.radii['3'],
- },
- '&::after': {
- boxSizing: 'border-box',
- content: '""',
- position: 'absolute',
- inset: 0,
- borderRadius: tokens.radii['3'],
- },
'&:focus-visible': {
- borderRadius: tokens.radii['3'],
- },
- '&:focus-visible::before': {
- backgroundColor: 'rgba(255, 255, 255, 0.15)',
- },
- '&:focus-visible::after': {
- opacity: 0.15,
+ backgroundImage: stateLayers(HOVER_LAYER),
},
'&[data-state=on]': {
backgroundColor: tokens.colors.buttonSwitchActiveBg,
color: tokens.colors.buttonSwitchActiveColor,
- borderRadius: tokens.radii['3'],
},
},
@@ -57,12 +40,7 @@ export const buttonSwitchItem = style({
selectors: {
'&:hover': {
cursor: 'pointer',
- },
- '&:hover::before': {
- backgroundColor: 'rgba(255, 255, 255, 0.15)',
- },
- '&:hover::after': {
- opacity: 0.05,
+ backgroundImage: stateLayers(HOVER_LAYER),
},
},
},
diff --git a/components/Checkbox/Checkbox.vanilla.css.ts b/components/Checkbox/Checkbox.vanilla.css.ts
index 968f07e7..614ebdb2 100644
--- a/components/Checkbox/Checkbox.vanilla.css.ts
+++ b/components/Checkbox/Checkbox.vanilla.css.ts
@@ -45,12 +45,6 @@ export const checkboxRecipe = recipe({
overflow: 'hidden',
selectors: {
- '&::before': {
- boxSizing: 'border-box',
- },
- '&::after': {
- boxSizing: 'border-box',
- },
'&[data-state=checked], &[data-state=indeterminate]': {
backgroundColor: tokens.colors.checkboxCheckedBg,
boxShadow: 'inset 0 0 0 1px transparent',
diff --git a/components/IconButton/IconButton.vanilla.css.ts b/components/IconButton/IconButton.vanilla.css.ts
index b3eadbb7..2e252b18 100644
--- a/components/IconButton/IconButton.vanilla.css.ts
+++ b/components/IconButton/IconButton.vanilla.css.ts
@@ -1,9 +1,12 @@
import { style } from '@vanilla-extract/css';
import { recipe, RecipeVariants } from '@vanilla-extract/recipes';
+import { stateLayers } from '@/styles/stateLayers';
import { tokens } from '@/styles/tokens.css';
-// Base button styles (matching BUTTON_BASE_STYLES from Button component)
+const HOVER_LAYER = 'rgba(255, 255, 255, 0.15)';
+const PRESSED_LAYER = 'rgba(0, 0, 0, 0.15)';
+
const baseIconButton = style({
// Reset
appearance: 'none',
@@ -29,37 +32,17 @@ const baseIconButton = style({
textDecoration: 'none',
backgroundColor: 'transparent',
- // Pseudo-elements for hover/active effects
selectors: {
- '&::before': {
- boxSizing: 'border-box',
- content: '""',
- position: 'absolute',
- inset: 0,
- borderRadius: 'inherit',
- },
- '&::after': {
- boxSizing: 'border-box',
- content: '""',
- position: 'absolute',
- inset: 0,
- borderRadius: 'inherit',
- },
'&:disabled': {
pointerEvents: 'none',
opacity: 0.5,
},
'&:focus-visible': {
outline: '2px solid currentColor',
+ backgroundImage: stateLayers(HOVER_LAYER),
},
- '&:focus-visible::before': {
- backgroundColor: 'rgba(255, 255, 255, 0.15)',
- },
- '&:focus-visible::after': {
- opacity: 0.15,
- },
- '&:active::before': {
- backgroundColor: 'rgba(0, 0, 0, 0.15)',
+ '&:active': {
+ backgroundImage: stateLayers(PRESSED_LAYER),
},
},
@@ -68,12 +51,7 @@ const baseIconButton = style({
selectors: {
'&:hover': {
cursor: 'pointer',
- },
- '&:hover::before': {
- backgroundColor: 'rgba(255, 255, 255, 0.15)',
- },
- '&:hover::after': {
- opacity: 0.05,
+ backgroundImage: stateLayers(HOVER_LAYER),
},
},
},
From fe3fba4471fd822413d3a2ee5f530e052bd630b1 Mon Sep 17 00:00:00 2001
From: gndz07 <70909035+gndz07@users.noreply.github.com>
Date: Thu, 26 Nov 2026 14:30:14 +0100
Subject: [PATCH 5/7] fix: align dropdown
---
BREAKING_CHANGES.md | 6 ++++--
components/DropdownMenu/DropdownMenu.vanilla.css.ts | 3 ++-
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md
index 2f07cd21..b89e5afb 100644
--- a/BREAKING_CHANGES.md
+++ b/BREAKING_CHANGES.md
@@ -537,7 +537,7 @@ globalStyle(`${monoInput} input`, { fontFamily: 'monospace' });
**Change:** Hover and active backgrounds are drawn as `background-image` layers on the element itself, over its `background-color`, instead of on `::before` and `::after`.
-**Affected:** `AccordionTrigger`, interactive `Badge`, `Button`, `ButtonSwitch`, `Card` (and so `Alert`), `IconButton`, interactive `Li`, `SelectTrigger`, the wrapper of `Input` and `Textarea` (and so `TextField` and `DateTimePickerInput`)
+**Affected:** `AccordionTrigger`, interactive `Badge`, `Button`, `ButtonSwitch`, `Card` (and so `Alert`), highlighted `DropdownMenuItem`, `IconButton`, interactive `Li`, `SelectTrigger`, the wrapper of `Input` and `Textarea` (and so `TextField` and `DateTimePickerInput`)
| | Before | After |
| ----------------------- | ----------------------------------------------- | ----------------------------------------------------------------------- |
@@ -551,6 +551,8 @@ globalStyle(`${monoInput} input`, { fontFamily: 'monospace' });
The `Input` and `Textarea` wrappers also lose a `:focus-visible` background that never showed, since the wrapper cannot take focus.
+The highlighted `DropdownMenuItem` background was a `background-color` and is now a layer too, so a custom item background no longer hides the highlight.
+
A `box-shadow` set on an `Alert` through `css` or `className` now replaces its ring too.
`Button` still uses `::after` for the `waiting` stripes, which no longer fade while the button has keyboard focus.
@@ -927,7 +929,7 @@ Release notes are generated by semantic-release; use this as the body of the bre
#### State Backgrounds
-- **Changed:** `AccordionTrigger`, interactive `Badge`, `Button`, `ButtonSwitch`, `Card`, `Alert`, `IconButton`, interactive `Li`, `SelectTrigger` and the `Input` and `Textarea` wrappers draw hover and active backgrounds as `background-image` layers instead of `::before`/`::after`; `Card` outlines and the `Alert` ring move to the element
+- **Changed:** `AccordionTrigger`, interactive `Badge`, `Button`, `ButtonSwitch`, `Card`, `Alert`, `DropdownMenuItem`, `IconButton`, interactive `Li`, `SelectTrigger` and the `Input` and `Textarea` wrappers draw hover and active backgrounds as `background-image` layers instead of `::before`/`::after`; `Card` outlines and the `Alert` ring move to the element
- Migration: move pseudo-element overrides to the element itself
- See [Migration Guide](./BREAKING_CHANGES.md#state-backgrounds-layers-instead-of-pseudo-elements)
diff --git a/components/DropdownMenu/DropdownMenu.vanilla.css.ts b/components/DropdownMenu/DropdownMenu.vanilla.css.ts
index 1e111a47..a662a654 100644
--- a/components/DropdownMenu/DropdownMenu.vanilla.css.ts
+++ b/components/DropdownMenu/DropdownMenu.vanilla.css.ts
@@ -1,6 +1,7 @@
import { style } from '@vanilla-extract/css';
import { recipe } from '@vanilla-extract/recipes';
+import { stateLayers } from '@/styles/stateLayers';
import { tokens } from '@/styles/tokens.css';
import { elevationVariants } from '@/components/Elevation/Elevation.vanilla.css';
@@ -49,7 +50,7 @@ export const dropdownMenuItem = style({
selectors: {
'&[data-highlighted]': {
- backgroundColor: tokens.colors.blue['9'],
+ backgroundImage: stateLayers(tokens.colors.blue['9']),
color: 'white',
},
'&[data-disabled]': {
From 4f13ea2b24b92ec72c3755ac838d7d6de257cbf2 Mon Sep 17 00:00:00 2001
From: gndz07 <70909035+gndz07@users.noreply.github.com>
Date: Thu, 26 Nov 2026 14:34:32 +0100
Subject: [PATCH 6/7] fix: align to use stateLayer
---
BREAKING_CHANGES.md | 6 +++---
components/Checkbox/Checkbox.vanilla.css.ts | 5 +++--
components/Combobox/Combobox.vanilla.css.ts | 3 ++-
.../SegmentedControl.vanilla.css.ts | 11 ++++++++---
components/Select/Select.vanilla.css.ts | 2 +-
components/Table/Table.vanilla.css.ts | 16 +++++++++++-----
6 files changed, 28 insertions(+), 15 deletions(-)
diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md
index b89e5afb..16159c6d 100644
--- a/BREAKING_CHANGES.md
+++ b/BREAKING_CHANGES.md
@@ -537,7 +537,7 @@ globalStyle(`${monoInput} input`, { fontFamily: 'monospace' });
**Change:** Hover and active backgrounds are drawn as `background-image` layers on the element itself, over its `background-color`, instead of on `::before` and `::after`.
-**Affected:** `AccordionTrigger`, interactive `Badge`, `Button`, `ButtonSwitch`, `Card` (and so `Alert`), highlighted `DropdownMenuItem`, `IconButton`, interactive `Li`, `SelectTrigger`, the wrapper of `Input` and `Textarea` (and so `TextField` and `DateTimePickerInput`)
+**Affected:** `AccordionTrigger`, interactive `Badge`, `Button`, `ButtonSwitch`, `Card` (and so `Alert`), `Checkbox` hover, highlighted `Combobox` option, `DropdownMenuItem` and `SelectItem`, `IconButton`, interactive `Li`, `SegmentedControlItem` hover, `SelectTrigger`, interactive and active `Tr`, the wrapper of `Input` and `Textarea` (and so `TextField` and `DateTimePickerInput`)
| | Before | After |
| ----------------------- | ----------------------------------------------- | ----------------------------------------------------------------------- |
@@ -551,7 +551,7 @@ globalStyle(`${monoInput} input`, { fontFamily: 'monospace' });
The `Input` and `Textarea` wrappers also lose a `:focus-visible` background that never showed, since the wrapper cannot take focus.
-The highlighted `DropdownMenuItem` background was a `background-color` and is now a layer too, so a custom item background no longer hides the highlight.
+The `Checkbox` and `SegmentedControlItem` hover, the highlighted `Combobox` option, `DropdownMenuItem` and `SelectItem`, and the interactive and active `Tr` backgrounds were a `background-color` and are now layers too, so a custom background no longer hides them. The interactive `Tr` and `SegmentedControlItem` hovers now only apply on devices that can hover, and the `SegmentedControlItem` hover no longer fades in.
A `box-shadow` set on an `Alert` through `css` or `className` now replaces its ring too.
@@ -929,7 +929,7 @@ Release notes are generated by semantic-release; use this as the body of the bre
#### State Backgrounds
-- **Changed:** `AccordionTrigger`, interactive `Badge`, `Button`, `ButtonSwitch`, `Card`, `Alert`, `DropdownMenuItem`, `IconButton`, interactive `Li`, `SelectTrigger` and the `Input` and `Textarea` wrappers draw hover and active backgrounds as `background-image` layers instead of `::before`/`::after`; `Card` outlines and the `Alert` ring move to the element
+- **Changed:** `AccordionTrigger`, interactive `Badge`, `Button`, `ButtonSwitch`, `Card`, `Alert`, `Checkbox`, `Combobox` options, `DropdownMenuItem`, `IconButton`, interactive `Li`, `SegmentedControlItem`, `SelectItem`, `SelectTrigger`, `Tr` and the `Input` and `Textarea` wrappers draw hover and active backgrounds as `background-image` layers instead of `::before`/`::after`; `Card` outlines and the `Alert` ring move to the element
- Migration: move pseudo-element overrides to the element itself
- See [Migration Guide](./BREAKING_CHANGES.md#state-backgrounds-layers-instead-of-pseudo-elements)
diff --git a/components/Checkbox/Checkbox.vanilla.css.ts b/components/Checkbox/Checkbox.vanilla.css.ts
index 614ebdb2..2b073150 100644
--- a/components/Checkbox/Checkbox.vanilla.css.ts
+++ b/components/Checkbox/Checkbox.vanilla.css.ts
@@ -1,6 +1,7 @@
import { style } from '@vanilla-extract/css';
import { recipe } from '@vanilla-extract/recipes';
+import { stateLayers } from '@/styles/stateLayers';
import { tokens } from '@/styles/tokens.css';
export const checkboxIndicator = style({
@@ -74,10 +75,10 @@ export const checkboxRecipe = recipe({
'(any-hover: hover)': {
selectors: {
'&[data-state=checked]:hover, &[data-state=indeterminate]:hover': {
- backgroundColor: tokens.colors.checkboxCheckedHoverBg,
+ backgroundImage: stateLayers(tokens.colors.checkboxCheckedHoverBg),
},
'&[data-state=unchecked]:hover': {
- backgroundColor: tokens.colors.checkboxHoverBg,
+ backgroundImage: stateLayers(tokens.colors.checkboxHoverBg),
boxShadow: `inset 0 0 0 1px ${tokens.colors.checkboxHoverBorder}`,
},
},
diff --git a/components/Combobox/Combobox.vanilla.css.ts b/components/Combobox/Combobox.vanilla.css.ts
index b0b2ce16..6729f5d9 100644
--- a/components/Combobox/Combobox.vanilla.css.ts
+++ b/components/Combobox/Combobox.vanilla.css.ts
@@ -1,6 +1,7 @@
import { style } from '@vanilla-extract/css';
import { recipe } from '@vanilla-extract/recipes';
+import { stateLayers } from '@/styles/stateLayers';
import { tokens } from '@/styles/tokens.css';
export const comboboxAnchor = style({
@@ -39,7 +40,7 @@ export const comboboxOptionRecipe = recipe({
selectors: {
'&[data-highlighted]': {
- backgroundColor: tokens.colors.comboboxOptionHighlightBg,
+ backgroundImage: stateLayers(tokens.colors.comboboxOptionHighlightBg),
},
},
},
diff --git a/components/SegmentedControl/SegmentedControl.vanilla.css.ts b/components/SegmentedControl/SegmentedControl.vanilla.css.ts
index 8745dbce..05e04598 100644
--- a/components/SegmentedControl/SegmentedControl.vanilla.css.ts
+++ b/components/SegmentedControl/SegmentedControl.vanilla.css.ts
@@ -2,6 +2,7 @@ import { recipe } from '@vanilla-extract/recipes';
import { breakpoints } from '@/styles/breakpoints.css';
import type { RecipeVariantProps } from '@/styles/recipeVariants';
+import { stateLayers } from '@/styles/stateLayers';
import { tokens } from '@/styles/tokens.css';
export const segmentedControlRecipe = recipe({
@@ -50,9 +51,6 @@ export const segmentedControlItemRecipe = recipe({
'& + &': {
borderLeft: `1px solid ${tokens.colors.segmentedControlBorder}`,
},
- '&:hover:not([data-state="checked"]):not([data-disabled])': {
- backgroundColor: tokens.colors.segmentedControlHoverBg,
- },
'&[data-state="checked"]': {
backgroundColor: tokens.colors.segmentedControlActiveBg,
color: tokens.colors.segmentedControlActiveText,
@@ -68,6 +66,13 @@ export const segmentedControlItemRecipe = recipe({
},
'@media': {
+ [breakpoints.hover]: {
+ selectors: {
+ '&:hover:not([data-state="checked"]):not([data-disabled])': {
+ backgroundImage: stateLayers(tokens.colors.segmentedControlHoverBg),
+ },
+ },
+ },
[breakpoints.motion]: {
transition: 'none',
},
diff --git a/components/Select/Select.vanilla.css.ts b/components/Select/Select.vanilla.css.ts
index 64f60cc1..71644298 100644
--- a/components/Select/Select.vanilla.css.ts
+++ b/components/Select/Select.vanilla.css.ts
@@ -188,7 +188,7 @@ export const selectItemRecipe = recipe({
selectors: {
'&[data-highlighted]': {
- backgroundColor: tokens.colors.comboboxOptionHighlightBg,
+ backgroundImage: stateLayers(tokens.colors.comboboxOptionHighlightBg),
},
'&[data-disabled]': {
color: tokens.colors.textSubtle,
diff --git a/components/Table/Table.vanilla.css.ts b/components/Table/Table.vanilla.css.ts
index 86ac77ea..5eccab59 100644
--- a/components/Table/Table.vanilla.css.ts
+++ b/components/Table/Table.vanilla.css.ts
@@ -1,6 +1,8 @@
import { globalStyle, style } from '@vanilla-extract/css';
import { recipe } from '@vanilla-extract/recipes';
+import { breakpoints } from '@/styles/breakpoints.css';
+import { stateLayers } from '@/styles/stateLayers';
import {
colorVariants,
gradientVariants,
@@ -130,17 +132,21 @@ export const trRecipe = recipe({
variants: {
interactive: {
true: {
- selectors: {
- '&:hover': {
- backgroundColor: tokens.colors.tableHoverBackground,
- cursor: 'pointer',
+ '@media': {
+ [breakpoints.hover]: {
+ selectors: {
+ '&:hover': {
+ backgroundImage: stateLayers(tokens.colors.tableHoverBackground),
+ cursor: 'pointer',
+ },
+ },
},
},
},
},
active: {
true: {
- backgroundColor: tokens.colors.tableHoverBackground,
+ backgroundImage: stateLayers(tokens.colors.tableHoverBackground),
color: tokens.colors.tableActiveText,
fontWeight: tokens.fontWeights.semiBold,
},
From 009181e9aa5bf8f20cf34ee35c0b2c9adcef90f3 Mon Sep 17 00:00:00 2001
From: Massimiliano D'Elia
Date: Fri, 27 Nov 2026 14:16:35 +0100
Subject: [PATCH 7/7] fix: address review findings on state layers
---
BREAKING_CHANGES.md | 10 ++++-
components/Badge/Badge.vanilla.css.ts | 22 +++++++---
components/Button/Button.vanilla.css.ts | 3 +-
.../ButtonSwitch/ButtonSwitch.vanilla.css.ts | 4 +-
components/Card/Card.vanilla.css.ts | 20 +++++++--
.../DateTimePickerInput.stories.tsx | 15 ++++++-
.../DateTimePickerInput.vanilla.css.ts | 42 +++++++++++++------
.../IconButton/IconButton.vanilla.css.ts | 3 +-
components/List/List.vanilla.css.ts | 5 ++-
.../Navigation/Navigation.vanilla.css.ts | 17 ++++----
.../SegmentedControl.stories.tsx | 10 +++++
components/Select/Select.theme.ts | 1 +
components/Select/Select.vanilla.css.ts | 12 ++++++
styles/stateLayers.test.ts | 13 ++++++
styles/tokens.css.ts | 1 +
15 files changed, 142 insertions(+), 36 deletions(-)
create mode 100644 styles/stateLayers.test.ts
diff --git a/BREAKING_CHANGES.md b/BREAKING_CHANGES.md
index 16159c6d..f1c47fb5 100644
--- a/BREAKING_CHANGES.md
+++ b/BREAKING_CHANGES.md
@@ -549,9 +549,15 @@ globalStyle(`${monoInput} input`, { fontFamily: 'monospace' });
| `Card` state outline | on `::before` | on the element |
| `Alert` ring | inset `box-shadow` on `::before` | inset `box-shadow` on the element, before the elevation shadow |
-The `Input` and `Textarea` wrappers also lose a `:focus-visible` background that never showed, since the wrapper cannot take focus.
+The `Input` and `Textarea` wrappers also lose a `:focus-visible` background that never showed, since the wrapper cannot take focus. Their hover tint is now drawn under the inner control, so it no longer shows while the browser autofills the field or while a ghost field is focused, both of which paint an opaque background on the control.
-The `Checkbox` and `SegmentedControlItem` hover, the highlighted `Combobox` option, `DropdownMenuItem` and `SelectItem`, and the interactive and active `Tr` backgrounds were a `background-color` and are now layers too, so a custom background no longer hides them. The interactive `Tr` and `SegmentedControlItem` hovers now only apply on devices that can hover, and the `SegmentedControlItem` hover no longer fades in.
+On devices that can hover, `Button`, `IconButton`, interactive `Card` and interactive `Li` now show their pressed color while held, where the hover color used to win. An interactive `Card` with `active` keeps its active look on hover, and its focus ring only shows for keyboard focus (`:focus-visible`), so a mouse click no longer leaves it. The same goes for the interactive `Li` focus ring.
+
+In Firefox, the `DateTimePickerInput` patch over the native picker button follows the field: a red hover tint when invalid, and dimmed with no hover and no click when disabled. These states need `:has()` (Firefox 121 and later).
+
+An invalid `SelectTrigger` now gets the same red hover tint as an invalid `Input`, from the new `selectInvalidHoverTint` theme token, instead of the primary tint.
+
+The `Checkbox` and `SegmentedControlItem` hover, the highlighted `Combobox` option, `DropdownMenuItem` and `SelectItem`, and the interactive and active `Tr` backgrounds were a `background-color` and are now layers too, so a custom background no longer hides them. The interactive `Badge`, `Tr` and `SegmentedControlItem` hovers now only apply on devices that can hover, and the `SegmentedControlItem` hover no longer fades in.
A `box-shadow` set on an `Alert` through `css` or `className` now replaces its ring too.
diff --git a/components/Badge/Badge.vanilla.css.ts b/components/Badge/Badge.vanilla.css.ts
index c92008d0..6b03d643 100644
--- a/components/Badge/Badge.vanilla.css.ts
+++ b/components/Badge/Badge.vanilla.css.ts
@@ -1,6 +1,7 @@
import { style } from '@vanilla-extract/css';
import { recipe } from '@vanilla-extract/recipes';
+import { breakpoints } from '@/styles/breakpoints.css';
import { stateLayers } from '@/styles/stateLayers';
import { tokens } from '@/styles/tokens.css';
@@ -38,18 +39,29 @@ const baseBadge = style({
const interactiveBadge = style([
baseBadge,
{
+ // The layers fill the padding box only, so they don't tint the border; the base color still does.
+ backgroundRepeat: 'no-repeat',
+
selectors: {
'&:focus-visible': {
outline: `2px solid ${tokens.colors.primary}`,
},
- '&:hover': {
- cursor: 'pointer',
- backgroundImage: stateLayers(tokens.colors.badgeInteractiveBackgroundHover),
- },
- '&:active': {
+ // `:hover:active` outranks the hover rule, which comes later inside its media query.
+ '&:active, &:hover:active': {
backgroundImage: stateLayers(tokens.colors.badgeInteractiveBackgroundActive),
},
},
+
+ '@media': {
+ [breakpoints.hover]: {
+ selectors: {
+ '&:hover': {
+ cursor: 'pointer',
+ backgroundImage: stateLayers(tokens.colors.badgeInteractiveBackgroundHover),
+ },
+ },
+ },
+ },
},
]);
diff --git a/components/Button/Button.vanilla.css.ts b/components/Button/Button.vanilla.css.ts
index f335367c..450bb2f8 100644
--- a/components/Button/Button.vanilla.css.ts
+++ b/components/Button/Button.vanilla.css.ts
@@ -56,7 +56,8 @@ const baseButton = style({
boxShadow: `inset 0 0 0 2px ${tokens.colors.focusOutline}`,
backgroundImage: stateLayers(HOVER_LAYER),
},
- '&:active': {
+ // `:hover:active` outranks the hover rules, which come later inside their media query.
+ '&:active, &:hover:active': {
backgroundImage: stateLayers(PRESSED_LAYER),
},
},
diff --git a/components/ButtonSwitch/ButtonSwitch.vanilla.css.ts b/components/ButtonSwitch/ButtonSwitch.vanilla.css.ts
index 030e46b2..78432b63 100644
--- a/components/ButtonSwitch/ButtonSwitch.vanilla.css.ts
+++ b/components/ButtonSwitch/ButtonSwitch.vanilla.css.ts
@@ -22,16 +22,17 @@ export const buttonSwitchItem = style({
justifyContent: 'center',
fontWeight: 600,
border: 'none',
- borderRadius: tokens.radii['3'],
position: 'relative',
selectors: {
'&:focus-visible': {
+ borderRadius: tokens.radii['3'],
backgroundImage: stateLayers(HOVER_LAYER),
},
'&[data-state=on]': {
backgroundColor: tokens.colors.buttonSwitchActiveBg,
color: tokens.colors.buttonSwitchActiveColor,
+ borderRadius: tokens.radii['3'],
},
},
@@ -40,6 +41,7 @@ export const buttonSwitchItem = style({
selectors: {
'&:hover': {
cursor: 'pointer',
+ borderRadius: tokens.radii['3'],
backgroundImage: stateLayers(HOVER_LAYER),
},
},
diff --git a/components/Card/Card.vanilla.css.ts b/components/Card/Card.vanilla.css.ts
index d7e3882d..21b3acc3 100644
--- a/components/Card/Card.vanilla.css.ts
+++ b/components/Card/Card.vanilla.css.ts
@@ -5,8 +5,8 @@ import { breakpoints } from '@/styles/breakpoints.css';
import { stateLayers } from '@/styles/stateLayers';
import { tokens } from '@/styles/tokens.css';
-// Lets Alert add an inset ring without replacing the elevation shadow.
-export const cardRing = createVar();
+// Lets Alert add an inset ring without replacing the elevation shadow. Not inherited, so nested cards don't draw it.
+export const cardRing = createVar({ syntax: '*', inherits: false });
const ring = fallbackVar(cardRing, '0 0 #0000');
const elevationVariants = {
@@ -96,12 +96,13 @@ const interactiveCardBase = style([
},
},
selectors: {
- '&:active': {
+ // `:hover:active` outranks the hover rule, which comes later inside its media query.
+ '&:active, &:hover:active': {
outline: `1px solid ${tokens.colors.cardActiveBorder}`,
backgroundImage: stateLayers(tokens.colors.cardActiveBackground),
},
// Beats the hover and active outlines.
- '&:focus, &:focus:hover, &:focus:active': {
+ '&:focus-visible, &:focus-visible:hover, &:focus-visible:active': {
outline: `2px solid ${tokens.colors.primary}`,
},
},
@@ -126,6 +127,17 @@ export const interactiveCardRecipe = recipe({
true: {
outline: `1px solid ${tokens.colors.cardActiveBorder}`,
backgroundImage: stateLayers(tokens.colors.cardActiveBackground),
+ // Same media query as the base hover, so this later rule replaces it.
+ '@media': {
+ [breakpoints.hover]: {
+ selectors: {
+ '&:hover': {
+ outline: `1px solid ${tokens.colors.cardActiveBorder}`,
+ backgroundImage: stateLayers(tokens.colors.cardActiveBackground),
+ },
+ },
+ },
+ },
},
},
},
diff --git a/components/DateTimePickerInput/DateTimePickerInput.stories.tsx b/components/DateTimePickerInput/DateTimePickerInput.stories.tsx
index c0b3bb90..8f8e2415 100644
--- a/components/DateTimePickerInput/DateTimePickerInput.stories.tsx
+++ b/components/DateTimePickerInput/DateTimePickerInput.stories.tsx
@@ -11,6 +11,7 @@ import { FieldVanilla } from '../Field/Field.vanilla';
import { Flex } from '../Flex';
import { FlexVanilla } from '../Flex/Flex.vanilla';
import { H3Vanilla } from '../Heading';
+import { InputVanillaProps } from '../Input/Input.vanilla';
import { Label } from '../Label';
import { Text, TextVanilla } from '../Text';
import {
@@ -178,7 +179,13 @@ type ComparisonProps = Pick<
'labels' | 'showDatePresets' | 'showTimePicker' | 'time'
>;
-const COMPARISON_STATES: { label: string; props: ComparisonProps }[] = [
+type ComparisonInputProps = Pick;
+
+const COMPARISON_STATES: {
+ label: string;
+ props: ComparisonProps;
+ inputProps?: ComparisonInputProps;
+}[] = [
{ label: 'Base', props: {} },
{ label: 'With time picker and presets', props: { showTimePicker: true, showDatePresets: true } },
{
@@ -186,6 +193,8 @@ const COMPARISON_STATES: { label: string; props: ComparisonProps }[] = [
props: { showTimePicker: true, time: { minTime: { h: 9, m: 0 }, maxTime: { h: 18, m: 0 } } },
},
{ label: 'Custom labels (popup and arrow buttons)', props: { labels: CUSTOM_LABELS } },
+ { label: 'Disabled', props: {}, inputProps: { disabled: true } },
+ { label: 'Invalid', props: {}, inputProps: { state: 'invalid' } },
];
const LABEL_WIDTH = 180;
@@ -201,6 +210,7 @@ const ComparisonRow = ({
label,
minDate,
props,
+ inputProps,
}: (typeof COMPARISON_STATES)[number] & { minDate: Date }): JSX.Element => {
const [stitchesDates, setStitchesDates] = useState([]);
const [vanillaDates, setVanillaDates] = useState([]);
@@ -213,6 +223,8 @@ const ComparisonRow = ({
({ '@supports': { '(-moz-appearance: none)': rule } });
+const onHover = (rule: GlobalStyleRule) => inFirefox({ '@media': { [breakpoints.hover]: rule } });
+
+// Direct child only: adornments render inside the same wrapper and may hold inputs of their own.
+const field = `${input} > input`;
+
+globalStyle(
+ `${wrapper}:hover ${firefoxPatch}`,
+ onHover({ backgroundImage: stateLayers(tokens.colors.primaryTint, tokens.colors.inputHoverBg) }),
+);
+
+globalStyle(
+ `${wrapper}:hover:has(${field}[aria-invalid="true"]) ${firefoxPatch}`,
+ onHover({
+ backgroundImage: stateLayers(tokens.colors.inputInvalidHoverTint, tokens.colors.inputHoverBg),
+ }),
+);
+
+// Dimmed like the Input wrapper, and not clickable, so it can't open the picker.
+globalStyle(
+ `${wrapper}:has(${field}:disabled) ${firefoxPatch}`,
+ inFirefox({ opacity: 0.7, pointerEvents: 'none' }),
+);
+
+// Declared after the invalid rule, with the same specificity, so it wins.
+globalStyle(
+ `${wrapper}:hover:has(${field}:disabled) ${firefoxPatch}`,
+ onHover({ backgroundImage: 'none' }),
+);
diff --git a/components/IconButton/IconButton.vanilla.css.ts b/components/IconButton/IconButton.vanilla.css.ts
index 2e252b18..be67996f 100644
--- a/components/IconButton/IconButton.vanilla.css.ts
+++ b/components/IconButton/IconButton.vanilla.css.ts
@@ -41,7 +41,8 @@ const baseIconButton = style({
outline: '2px solid currentColor',
backgroundImage: stateLayers(HOVER_LAYER),
},
- '&:active': {
+ // `:hover:active` outranks the hover rules, which come later inside their media query.
+ '&:active, &:hover:active': {
backgroundImage: stateLayers(PRESSED_LAYER),
},
},
diff --git a/components/List/List.vanilla.css.ts b/components/List/List.vanilla.css.ts
index 45bf0a3e..39ea3f58 100644
--- a/components/List/List.vanilla.css.ts
+++ b/components/List/List.vanilla.css.ts
@@ -99,10 +99,11 @@ export const itemButton = style([
'&:disabled': {
opacity: 0.5,
},
- '&:focus, &:focus-visible': {
+ '&:focus-visible': {
boxShadow: `inset 0 0 0 2px ${tokens.colors.listItemFocusBorder}`,
},
- '&:enabled:active': {
+ // `:hover:active` outranks the hover rule, which comes later inside its media query.
+ '&:enabled:active, &:enabled:hover:active': {
backgroundImage: stateLayers(tokens.colors.primaryTint, tokens.colors.listItemActiveBg),
},
},
diff --git a/components/Navigation/Navigation.vanilla.css.ts b/components/Navigation/Navigation.vanilla.css.ts
index 36459128..15e1b9c0 100644
--- a/components/Navigation/Navigation.vanilla.css.ts
+++ b/components/Navigation/Navigation.vanilla.css.ts
@@ -2,14 +2,11 @@ import { globalStyle, style } from '@vanilla-extract/css';
import { recipe } from '@vanilla-extract/recipes';
import { breakpoints } from '@/styles/breakpoints.css';
+import { stateLayers } from '@/styles/stateLayers';
import { tokens } from '@/styles/tokens.css';
import { elevationVariants } from '@/components/Elevation/Elevation.vanilla.css';
-// State colors stack over `background-color`, so a custom base color keeps the hover, focus and active layers.
-const layers = (tint: string, color: string) =>
- `linear-gradient(${tint}, ${tint}), linear-gradient(${color}, ${color})`;
-
const negativeSpace1 = `calc(${tokens.space['1']} * -1)`;
export const navigationContainer = style({
@@ -48,11 +45,14 @@ export const navigationItem = style({
// `data-active` also comes from Radix when the item is the `as` of a NavigationMenuLink; `:where` lets hover and focus layers win.
'&:where([data-active])': {
color: tokens.colors.navButtonActiveText,
- backgroundImage: layers(tokens.colors.navButtonActiveBg2, tokens.colors.navButtonActiveBg),
+ backgroundImage: stateLayers(
+ tokens.colors.navButtonActiveBg2,
+ tokens.colors.navButtonActiveBg,
+ ),
},
'&:focus-visible': {
color: tokens.colors.navButtonFocusText,
- backgroundImage: layers(tokens.colors.navButtonFocusBg2, tokens.colors.navButtonFocusBg),
+ backgroundImage: stateLayers(tokens.colors.navButtonFocusBg2, tokens.colors.navButtonFocusBg),
boxShadow: `inset 0 0 0 2px ${tokens.colors.navButtonFocusBorder}`,
},
'&:where([data-active]):focus-visible': {
@@ -65,7 +65,10 @@ export const navigationItem = style({
selectors: {
'&:hover': {
color: tokens.colors.navButtonHoverText,
- backgroundImage: layers(tokens.colors.navButtonHoverBg2, tokens.colors.navButtonHoverBg),
+ backgroundImage: stateLayers(
+ tokens.colors.navButtonHoverBg2,
+ tokens.colors.navButtonHoverBg,
+ ),
},
'&:where([data-active]):hover': {
color: tokens.colors.navButtonActiveText,
diff --git a/components/SegmentedControl/SegmentedControl.stories.tsx b/components/SegmentedControl/SegmentedControl.stories.tsx
index a43c3713..1edae7c0 100644
--- a/components/SegmentedControl/SegmentedControl.stories.tsx
+++ b/components/SegmentedControl/SegmentedControl.stories.tsx
@@ -82,4 +82,14 @@ export const WithCount: StoryFn = (args) => (
);
+export const DisabledItem: StoryFn = (args) => (
+
+ Dev
+ Staging
+
+ Production
+
+
+);
+
export default Component;
diff --git a/components/Select/Select.theme.ts b/components/Select/Select.theme.ts
index 99638f80..ea5e24a3 100644
--- a/components/Select/Select.theme.ts
+++ b/components/Select/Select.theme.ts
@@ -9,6 +9,7 @@ const fromInputTheme = (input: typeof inputLightTheme) => ({
selectPlaceholder: input.inputPlaceholder,
selectDisabledText: input.inputDisabledText,
selectInvalidBorder: input.inputInvalidBorder,
+ selectInvalidHoverTint: input.inputInvalidHoverTint,
});
export const selectLightTheme = fromInputTheme(inputLightTheme);
diff --git a/components/Select/Select.vanilla.css.ts b/components/Select/Select.vanilla.css.ts
index 71644298..1482467f 100644
--- a/components/Select/Select.vanilla.css.ts
+++ b/components/Select/Select.vanilla.css.ts
@@ -116,6 +116,18 @@ export const selectTriggerRecipe = recipe({
boxShadow: `inset 0 0 0 2px ${tokens.colors.selectInvalidBorder}, ${FOCUS_SHADOW}`,
},
},
+ '@media': {
+ [breakpoints.hover]: {
+ selectors: {
+ '&:hover': {
+ backgroundImage: stateLayers(
+ tokens.colors.selectInvalidHoverTint,
+ tokens.colors.selectHoverBg,
+ ),
+ },
+ },
+ },
+ },
},
},
},
diff --git a/styles/stateLayers.test.ts b/styles/stateLayers.test.ts
new file mode 100644
index 00000000..8afd5bfb
--- /dev/null
+++ b/styles/stateLayers.test.ts
@@ -0,0 +1,13 @@
+import { stateLayers } from './stateLayers';
+
+describe('stateLayers', () => {
+ it('turns a color into a solid gradient layer', () => {
+ expect(stateLayers('red')).toBe('linear-gradient(red, red)');
+ });
+
+ it('keeps the first color on top', () => {
+ expect(stateLayers('var(--tint)', 'rgba(0, 0, 0, 0.1)')).toBe(
+ 'linear-gradient(var(--tint), var(--tint)), linear-gradient(rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.1))',
+ );
+ });
+});
diff --git a/styles/tokens.css.ts b/styles/tokens.css.ts
index 01d82112..24d67257 100644
--- a/styles/tokens.css.ts
+++ b/styles/tokens.css.ts
@@ -130,6 +130,7 @@ export const tokens = createThemeContract({
selectPlaceholder: null,
selectDisabledText: null,
selectInvalidBorder: null,
+ selectInvalidHoverTint: null,
textareaBg: null,
textareaBorder: null,