Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(core): ensure pressed overlays override hover (#5516)

Jiun Shin8bb01b1f095f
diff --git a/.changeset/pressed-overlay-specificity.md b/.changeset/pressed-overlay-specificity.md
new file mode 100644
index 0000000000..5703bfe191
--- /dev/null
+++ b/.changeset/pressed-overlay-specificity.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Ensure pressed overlays override hover across interactive surfaces (#5451)
+
+@jiunshinn
diff --git a/.github/scripts/pressed-overlay-cascade.js b/.github/scripts/pressed-overlay-cascade.js
new file mode 100644
index 0000000000..2825ad0fb1
--- /dev/null
+++ b/.github/scripts/pressed-overlay-cascade.js
@@ -0,0 +1,319 @@
+#!/usr/bin/env node
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @description Asserts hover yields to pressed overlays in built Astryx CSS
+ * @input [--css <path>] [--port <n>]
+ * @output Computed hover/pressed values for image and color overlays; exit 1
+ * when Chromium paints hover during :active or touch loses pressed feedback
+ *
+ * StyleX gives a media-nested rule another priority bucket. In selector-based
+ * output that bucket becomes generated specificity, so a guarded hover rule
+ * can beat a bare :active rule even though :active is the later interaction
+ * state. jsdom has neither pseudo-state forcing nor a cascade, so this probe
+ * reads the built stylesheet, applies its real atomic classes, and asks
+ * Chromium what paints while :hover and :active match together.
+ */
+
+const {chromium} = require('playwright');
+const fs = require('node:fs');
+const http = require('node:http');
+const path = require('node:path');
+
+const args = process.argv.slice(2);
+const getArg = name => {
+ const index = args.indexOf(`--${name}`);
+ return index === -1 ? null : args[index + 1];
+};
+
+const cssPath = path.resolve(
+ process.cwd(),
+ getArg('css') || 'packages/core/dist/astryx.css',
+);
+const port = Number(getArg('port') || 0);
+
+const TOKENS = {
+ hover: 'rgba(10, 20, 30, 0.25)',
+ pressed: 'rgba(40, 50, 60, 0.5)',
+ neutral: 'rgba(70, 80, 90, 0.2)',
+};
+
+function stateClass(css, {property, token, state, media, neutral = false}) {
+ const line = css.split('\n').find(candidate => {
+ const inHoverMedia = candidate.includes('@media (hover: hover)');
+ return (
+ inHoverMedia === media &&
+ candidate.includes(`:${state}:where(`) &&
+ !candidate.includes('::') &&
+ candidate.includes(`${property}:`) &&
+ candidate.includes(`var(--color-overlay-${token})`) &&
+ candidate.includes('var(--color-neutral)') === neutral
+ );
+ });
+ const className = line?.match(/\.([a-zA-Z][a-zA-Z0-9_-]*)/)?.[1];
+ if (!line || !className) {
+ throw new Error(
+ `Missing ${media ? 'media ' : ''}:${state} ${property} ` +
+ `${token}${neutral ? ' on neutral' : ''} rule in ${cssPath}`,
+ );
+ }
+ return className;
+}
+
+function classesFor(css, property, neutral = false) {
+ return [
+ stateClass(css, {
+ property,
+ token: 'hover',
+ state: 'hover',
+ media: true,
+ neutral,
+ }),
+ stateClass(css, {
+ property,
+ token: 'pressed',
+ state: 'active',
+ media: true,
+ neutral,
+ }),
+ stateClass(css, {
+ property,
+ token: 'pressed',
+ state: 'active',
+ media: false,
+ neutral,
+ }),
+ ].join(' ');
+}
+
+function pageMarkup(css) {
+ const vars = [
+ `--color-overlay-hover:${TOKENS.hover}`,
+ `--color-overlay-pressed:${TOKENS.pressed}`,
+ `--color-neutral:${TOKENS.neutral}`,
+ ].join(';');
+ return `<!doctype html>
+<html><head><link rel="stylesheet" href="/astryx.css"></head><body>
+ <button id="image" class="${classesFor(css, 'background-image')}" style="${vars}">image</button>
+ <button id="color" class="${classesFor(css, 'background-color')}" style="${vars}">color</button>
+ <button id="neutral" class="${classesFor(css, 'background-image', true)}" style="${vars}">neutral</button>
+ <button id="disabled" class="${classesFor(css, 'background-image')}" style="${vars}" disabled>disabled</button>
+</body></html>`;
+}
+
+function serve(css, html) {
+ return new Promise(resolve => {
+ const server = http.createServer((request, response) => {
+ if (request.url === '/astryx.css') {
+ response.writeHead(200, {'Content-Type': 'text/css'});
+ response.end(css);
+ return;
+ }
+ response.writeHead(200, {'Content-Type': 'text/html'});
+ response.end(html);
+ });
+ server.listen(port, '127.0.0.1', () =>
+ resolve({server, port: server.address().port}),
+ );
+ });
+}
+
+async function forceState(context, page, selector, states, property) {
+ const session = await context.newCDPSession(page);
+ try {
+ await session.send('DOM.enable');
+ await session.send('CSS.enable');
+ const {root} = await session.send('DOM.getDocument', {depth: -1});
+ const {nodeId} = await session.send('DOM.querySelector', {
+ nodeId: root.nodeId,
+ selector,
+ });
+ await session.send('CSS.forcePseudoState', {
+ nodeId,
+ forcedPseudoClasses: states,
+ });
+ return await page.$eval(
+ selector,
+ (element, name) => getComputedStyle(element).getPropertyValue(name),
+ property,
+ );
+ } finally {
+ await session.detach();
+ }
+}
+
+function checkIncludes(label, value, expected, failures) {
+ if (value.includes(expected)) {
+ console.log(`✓ ${label} — ${value}`);
+ } else {
+ failures.push(`${label}: got ${value}, expected it to include ${expected}`);
+ }
+}
+
+function checkEquals(label, value, expected, failures) {
+ if (value === expected) {
+ console.log(`✓ ${label} — ${value}`);
+ } else {
+ failures.push(`${label}: got ${value}, expected ${expected}`);
+ }
+}
+
+async function run() {
+ if (!fs.existsSync(cssPath)) {
+ throw new Error(
+ `${cssPath} is missing — run \`pnpm -F @astryxdesign/core build:css\` first.`,
+ );
+ }
+ const css = fs.readFileSync(cssPath, 'utf8');
+ const html = pageMarkup(css);
+ const {server, port: servedPort} = await serve(css, html);
+ const browser = await chromium.launch();
+ const failures = [];
+
+ try {
+ const desktop = await browser.newContext({
+ viewport: {width: 480, height: 240},
+ });
+ const desktopPage = await desktop.newPage();
+ await desktopPage.goto(`http://127.0.0.1:${servedPort}`, {
+ waitUntil: 'networkidle',
+ });
+ const imageHover = await forceState(
+ desktop,
+ desktopPage,
+ '#image',
+ ['hover'],
+ 'background-image',
+ );
+ const imagePressed = await forceState(
+ desktop,
+ desktopPage,
+ '#image',
+ ['hover', 'active'],
+ 'background-image',
+ );
+ const colorHover = await forceState(
+ desktop,
+ desktopPage,
+ '#color',
+ ['hover'],
+ 'background-color',
+ );
+ const colorPressed = await forceState(
+ desktop,
+ desktopPage,
+ '#color',
+ ['hover', 'active'],
+ 'background-color',
+ );
+ const neutralPressed = await forceState(
+ desktop,
+ desktopPage,
+ '#neutral',
+ ['hover', 'active'],
+ 'background-image',
+ );
+ const disabledHover = await forceState(
+ desktop,
+ desktopPage,
+ '#disabled',
+ ['hover'],
+ 'background-image',
+ );
+
+ checkIncludes(
+ 'image hover paints the hover token',
+ imageHover,
+ TOKENS.hover,
+ failures,
+ );
+ checkIncludes(
+ 'image press paints the pressed token',
+ imagePressed,
+ TOKENS.pressed,
+ failures,
+ );
+ checkIncludes(
+ 'color hover paints the hover token',
+ colorHover,
+ TOKENS.hover,
+ failures,
+ );
+ checkIncludes(
+ 'color press paints the pressed token',
+ colorPressed,
+ TOKENS.pressed,
+ failures,
+ );
+ checkIncludes(
+ 'neutral press keeps its base layer',
+ neutralPressed,
+ TOKENS.neutral,
+ failures,
+ );
+ checkIncludes(
+ 'neutral press paints the pressed token',
+ neutralPressed,
+ TOKENS.pressed,
+ failures,
+ );
+ checkEquals(
+ 'disabled hover remains unpainted',
+ disabledHover,
+ 'none',
+ failures,
+ );
+ await desktop.close();
+
+ const touch = await browser.newContext({
+ hasTouch: true,
+ isMobile: true,
+ viewport: {width: 390, height: 844},
+ });
+ const touchPage = await touch.newPage();
+ await touchPage.goto(`http://127.0.0.1:${servedPort}`, {
+ waitUntil: 'networkidle',
+ });
+ const hoverCapable = await touchPage.evaluate(
+ () => matchMedia('(hover: hover)').matches,
+ );
+ if (hoverCapable) {
+ failures.push('touch context unexpectedly matches (hover: hover)');
+ }
+ const touchPressed = await forceState(
+ touch,
+ touchPage,
+ '#image',
+ ['active'],
+ 'background-image',
+ );
+ checkIncludes(
+ 'touch keeps the bare pressed fallback',
+ touchPressed,
+ TOKENS.pressed,
+ failures,
+ );
+ await touch.close();
+ } finally {
+ await browser.close();
+ server.close();
+ }
+
+ if (failures.length > 0) {
+ for (const failure of failures) console.error(`✗ ${failure}`);
+ return 1;
+ }
+ console.log('\nHover yields to pressed, and touch retains pressed feedback.');
+ return 0;
+}
+
+if (require.main === module) {
+ run()
+ .then(code => {
+ process.exitCode = code;
+ })
+ .catch(error => {
+ console.error('Pressed-overlay cascade guard failed:', error);
+ process.exit(1);
+ });
+}
diff --git a/package.json b/package.json
index 6da1914c33..8396fe68cf 100644
--- a/package.json
+++ b/package.json
@@ -38,6 +38,7 @@
"guard:theme-vars": "node .github/scripts/theme-var-reachability.js",
"guard:theme-layers": "node .github/scripts/theme-layer-cascade.js",
"guard:disabled-hover": "node .github/scripts/disabled-hover-audit.js",
+ "guard:pressed-overlay": "node .github/scripts/pressed-overlay-cascade.js",
"guard:disabled-cursor": "node .github/scripts/disabled-cursor-audit.js",
"storybook": "pnpm -F @astryxdesign/storybook dev",
"storybook:build": "pnpm -F @astryxdesign/storybook build",
diff --git a/packages/core/src/AvatarGroup/AvatarGroupOverflow.tsx b/packages/core/src/AvatarGroup/AvatarGroupOverflow.tsx
index f84a0b1722..f5363d275e 100644
--- a/packages/core/src/AvatarGroup/AvatarGroupOverflow.tsx
+++ b/packages/core/src/AvatarGroup/AvatarGroupOverflow.tsx
@@ -29,6 +29,7 @@ import {useAvatarGroup} from './AvatarGroupContext';
import type {BaseProps} from '../BaseProps';
import {themeProps} from '../utils/themeProps';
import {focusOutlineProps} from '../utils/focusOutline.stylex';
+import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
import {useTranslator} from '../i18n';
const BORDER_WIDTH = 2;
@@ -96,14 +97,6 @@ const styles = stylex.create({
// Reset the UA button's block padding only; the inline padding from `base`
// provides the pill's breathing room and must be preserved.
paddingBlock: 0,
- // Interactive overlay states layered on top via backgroundImage
- backgroundImage: {
- default: `linear-gradient(${colorVars['--color-neutral']}, ${colorVars['--color-neutral']})`,
- ':hover:where(:not(:disabled,[aria-disabled="true"]))': {
- '@media (hover: hover)': `linear-gradient(${colorVars['--color-overlay-hover']}, ${colorVars['--color-overlay-hover']}), linear-gradient(${colorVars['--color-neutral']}, ${colorVars['--color-neutral']})`,
- },
- ':active': `linear-gradient(${colorVars['--color-overlay-pressed']}, ${colorVars['--color-overlay-pressed']}), linear-gradient(${colorVars['--color-neutral']}, ${colorVars['--color-neutral']})`,
- },
// Focus ring via focus-visible
},
overlap: {
@@ -194,6 +187,7 @@ export function AvatarGroupOverflow({
focusOutlineProps.focusVisible(
styles.base,
styles.button,
+ interactionOverlayStyles.backgroundImageOnNeutral,
styles.overlap,
dynamicStyles.size(numericSize),
dynamicStyles.fontSize(numericSize),
diff --git a/packages/core/src/Button/Button.tsx b/packages/core/src/Button/Button.tsx
index c261975aad..f982254829 100644
--- a/packages/core/src/Button/Button.tsx
+++ b/packages/core/src/Button/Button.tsx
@@ -48,6 +48,7 @@ import {useLinkComponent} from '../Link/useLinkComponent';
import type {LinkComponentType} from '../Link/types';
import {themeProps} from '../utils/themeProps';
import {focusOutlineProps} from '../utils/focusOutline.stylex';
+import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
import {useTranslator} from '../i18n';
import type {ButtonVariantMap} from './index';
@@ -200,35 +201,14 @@ const variants = stylex.create({
primary: {
backgroundColor: colorVars['--color-accent'],
color: colorVars['--color-on-accent'],
- backgroundImage: {
- default: null,
- ':hover:where(:not(:disabled,[aria-disabled="true"]))': {
- '@media (hover: hover)': `linear-gradient(${colorVars['--color-overlay-hover']}, ${colorVars['--color-overlay-hover']})`,
- },
- ':active': `linear-gradient(${colorVars['--color-overlay-pressed']}, ${colorVars['--color-overlay-pressed']})`,
- },
},
secondary: {
backgroundColor: colorVars['--color-neutral'],
color: colorVars['--color-text-primary'],
- backgroundImage: {
- default: null,
- ':hover:where(:not(:disabled,[aria-disabled="true"]))': {
- '@media (hover: hover)': `linear-gradient(${colorVars['--color-overlay-hover']}, ${colorVars['--color-overlay-hover']})`,
- },
- ':active': `linear-gradient(${colorVars['--color-overlay-pressed']}, ${colorVars['--color-overlay-pressed']})`,
- },
},
ghost: {
backgroundColor: 'transparent',
color: colorVars['--color-text-primary'],
- backgroundImage: {
- default: null,
- ':hover:where(:not(:disabled,[aria-disabled="true"]))': {
- '@media (hover: hover)': `linear-gradient(${colorVars['--color-overlay-hover']}, ${colorVars['--color-overlay-hover']})`,
- },
- ':active': `linear-gradient(${colorVars['--color-overlay-pressed']}, ${colorVars['--color-overlay-pressed']})`,
- },
},
destructive: {
backgroundColor: colorVars['--color-error'],
@@ -237,13 +217,6 @@ const variants = stylex.create({
// red button reads as another control's focus. Only the color differs —
// width, style and offset come from the shared outline.
outlineColor: {default: null, ':focus-visible': colorVars['--color-error']},
- backgroundImage: {
- default: null,
- ':hover:where(:not(:disabled,[aria-disabled="true"]))': {
- '@media (hover: hover)': `linear-gradient(${colorVars['--color-overlay-hover']}, ${colorVars['--color-overlay-hover']})`,
- },
- ':active': `linear-gradient(${colorVars['--color-overlay-pressed']}, ${colorVars['--color-overlay-pressed']})`,
- },
},
});
@@ -665,6 +638,7 @@ export function Button({
styles.base,
sizeStyles[size],
isIconOnly && styles.iconOnly,
+ interactionOverlayStyles.backgroundImage,
buttonDisabled && styles.disabled,
useAriaDisabled && styles.ariaDisabled,
renderAsLink && styles.link,
diff --git a/packages/core/src/Calendar/Calendar.tsx b/packages/core/src/Calendar/Calendar.tsx
index 1d15a169a8..13d62b98c8 100644
--- a/packages/core/src/Calendar/Calendar.tsx
+++ b/packages/core/src/Calendar/Calendar.tsx
@@ -61,6 +61,7 @@ import {
} from '../utils/plainDate';
import {mergeProps, composeEventHandlers, rtlStyles} from '../utils';
import {focusOutlineProps} from '../utils/focusOutline.stylex';
+import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
import {getInitialFocusDate} from './getInitialFocusDate';
import {
computeDayCellState,
@@ -1179,6 +1180,7 @@ function DayCell({
focusOutlineProps.focusVisible(
dayCellStyles.day,
dayCellTheme.day,
+ interactionOverlayStyles.backgroundImage,
isOutside && dayCellStyles.dayOutside,
isOutside && dayCellTheme.dayOutside,
showsTodayRing && dayCellStyles.dayToday,
diff --git a/packages/core/src/Calendar/styles.ts b/packages/core/src/Calendar/styles.ts
index 018bbdb2af..0d8a5f9a6e 100644
--- a/packages/core/src/Calendar/styles.ts
+++ b/packages/core/src/Calendar/styles.ts
@@ -259,12 +259,6 @@ export const dayCellTheme = stylex.create({
day: {
color: colorVars['--color-text-primary'],
backgroundColor: 'transparent',
- backgroundImage: {
- default: null,
- ':hover:where(:not(:disabled,[aria-disabled="true"]))': {
- '@media (hover: hover)': `linear-gradient(${colorVars['--color-overlay-hover']}, ${colorVars['--color-overlay-hover']})`,
- },
- },
},
// Outside days (adjacent months)
@@ -300,12 +294,6 @@ export const dayCellTheme = stylex.create({
default: colorVars['--color-on-accent'],
'@media (forced-colors: active)': 'HighlightText',
},
- backgroundImage: {
- default: null,
- ':hover:where(:not(:disabled,[aria-disabled="true"]))': {
- '@media (hover: hover)': `linear-gradient(${colorVars['--color-overlay-hover']}, ${colorVars['--color-overlay-hover']})`,
- },
- },
},
// Disabled state
diff --git a/packages/core/src/CommandPalette/CommandPaletteItem.tsx b/packages/core/src/CommandPalette/CommandPaletteItem.tsx
index 9133de46c8..facb3c6420 100644
--- a/packages/core/src/CommandPalette/CommandPaletteItem.tsx
+++ b/packages/core/src/CommandPalette/CommandPaletteItem.tsx
@@ -26,9 +26,9 @@ import {
import {useCommandPaletteContext} from './CommandPaletteContext';
import {useDialogContext} from '../Dialog/DialogContext';
import {themeProps} from '../utils/themeProps';
+import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
import {useMergedRefs} from '../hooks/useMergedRefs';
-const HOVER_HOVER = '@media (hover: hover)';
const styles = stylex.create({
item: {
@@ -52,16 +52,6 @@ const styles = stylex.create({
outline: 'none',
userSelect: 'none',
},
- itemHover: {
- ':hover:where(:not(:disabled,[aria-disabled="true"]))': {
- [HOVER_HOVER]: {
- backgroundColor: colorVars['--color-overlay-hover'],
- },
- },
- ':active': {
- backgroundColor: colorVars['--color-overlay-pressed'],
- },
- },
itemHighlighted: {
backgroundColor: colorVars['--color-overlay-hover'],
},
@@ -205,7 +195,7 @@ export function CommandPaletteItem({
themeProps('command-palette-item'),
stylex.props(
styles.item,
- !isDisabled && styles.itemHover,
+ !isDisabled && interactionOverlayStyles.backgroundColor,
isHighlighted && styles.itemHighlighted,
isSelected && styles.itemSelected,
isDisabled && styles.itemDisabled,
diff --git a/packages/core/src/ComplexSelector/ComplexSelector.tsx b/packages/core/src/ComplexSelector/ComplexSelector.tsx
index c8104e375e..ac7e289cca 100644
--- a/packages/core/src/ComplexSelector/ComplexSelector.tsx
+++ b/packages/core/src/ComplexSelector/ComplexSelector.tsx
@@ -50,6 +50,7 @@ import {
import {isRenderable, mergeProps} from '../utils';
import {composeEventHandlers} from '../utils/composeEventHandlers';
import {focusOutlineStyles} from '../utils/focusOutline.stylex';
+import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
import type {SizeValue} from '../utils/types';
import {themeProps} from '../utils/themeProps';
@@ -115,13 +116,6 @@ const styles = stylex.create({
width: 'auto',
borderWidth: 0,
backgroundColor: 'transparent',
- backgroundImage: {
- default: null,
- ':hover:where(:not(:disabled,[aria-disabled="true"]))': {
- '@media (hover: hover)': `linear-gradient(${colorVars['--color-overlay-hover']}, ${colorVars['--color-overlay-hover']})`,
- },
- ':active': `linear-gradient(${colorVars['--color-overlay-pressed']}, ${colorVars['--color-overlay-pressed']})`,
- },
boxShadow: {
default: 'none',
':hover:not(:focus-within):where(:not(:disabled,[aria-disabled="true"]))':
@@ -502,6 +496,7 @@ export function ComplexSelector<Value>({
// pointer users too. `focusWithin` here is `:has(:focus-visible)`.
focusOutlineStyles.focusWithin,
variant === 'ghost' && styles.triggerGhost,
+ variant === 'ghost' && interactionOverlayStyles.backgroundImage,
isDisabled && inputWrapperStyles.disabled,
variant === 'ghost' && isDisabled && styles.triggerGhostDisabled,
isDisabled && styles.disabled,
diff --git a/packages/core/src/DateInput/TouchDateField.tsx b/packages/core/src/DateInput/TouchDateField.tsx
index c3ef021048..2827d452b7 100644
--- a/packages/core/src/DateInput/TouchDateField.tsx
+++ b/packages/core/src/DateInput/TouchDateField.tsx
@@ -110,6 +110,7 @@ import {
DATE_FORMAT_WEEKDAY_ONLY,
type ISODateString,
} from '../utils';
+import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
import {normalizeDayOfWeek} from '../utils/dateTypes';
import {MonthScroller, type MonthScrollerHandle} from './MonthScroller';
import {MonthYearWheels} from './MonthYearWheels';
@@ -341,15 +342,7 @@ const styles = stylex.create({
borderWidth: 0,
borderStyle: 'none',
borderRadius: radiusVars['--radius-element'],
- backgroundColor: {
- default: 'transparent',
- '@media (hover: hover)': {
- default: 'transparent',
- ':hover:where(:not(:disabled,[aria-disabled="true"]))':
- colorVars['--color-overlay-hover'],
- },
- ':active': colorVars['--color-overlay-pressed'],
- },
+ backgroundColor: 'transparent',
color: colorVars['--color-text-primary'],
fontSize: typeScaleVars['--text-large-size'],
fontWeight: fontWeightVars['--font-weight-semibold'],
@@ -954,7 +947,11 @@ export function TouchDateField({
// restyle the header button. Adding a target later is additive;
// withdrawing one is not.
data-title="month-year"
- {...stylex.props(styles.title, focusOutlineStyles.focusVisible)}>
+ {...stylex.props(
+ styles.title,
+ interactionOverlayStyles.backgroundColor,
+ focusOutlineStyles.focusVisible,
+ )}>
<span {...stylex.props(styles.titleText)}>{monthYearLabel}</span>
<Icon
icon="chevronDown"
diff --git a/packages/core/src/Item/Item.tsx b/packages/core/src/Item/Item.tsx
index e4ef22f71e..36caacb1d3 100644
--- a/packages/core/src/Item/Item.tsx
+++ b/packages/core/src/Item/Item.tsx
@@ -35,6 +35,7 @@ import {useClickableContainer} from '../hooks/useClickableContainer';
import {useDevWarning} from '../hooks/useDevWarning';
import {themeProps} from '../utils/themeProps';
import {focusOutlineProps} from '../utils/focusOutline.stylex';
+import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
// =============================================================================
// Types
@@ -224,13 +225,6 @@ const styles = stylex.create({
transitionProperty: 'background-color',
transitionDuration: durationVars['--duration-fast-min'],
transitionTimingFunction: easeVars['--ease-standard'],
- backgroundColor: {
- default: 'transparent',
- ':hover:where(:not(:disabled,[aria-disabled="true"]))': {
- '@media (hover: hover)': colorVars['--color-overlay-hover'],
- },
- ':active': colorVars['--color-overlay-pressed'],
- },
},
highlighted: {
backgroundColor: colorVars['--color-overlay-hover'],
@@ -603,6 +597,7 @@ export function Item({
densityStyles[density],
align === 'start' && styles.alignStart,
isInteractive && styles.interactive,
+ isInteractive && interactionOverlayStyles.backgroundColor,
isHighlighted && styles.highlighted,
isSelected && styles.selected,
isDisabled && !hasParentRole && styles.disabled,
diff --git a/packages/core/src/MultiSelector/MultiSelector.tsx b/packages/core/src/MultiSelector/MultiSelector.tsx
index 56ee792200..bb16c43cd2 100644
--- a/packages/core/src/MultiSelector/MultiSelector.tsx
+++ b/packages/core/src/MultiSelector/MultiSelector.tsx
@@ -80,6 +80,7 @@ import type {SizeValue} from '../utils/types';
import {useSize} from '../SizeContext/SizeContext';
import {themeProps} from '../utils/themeProps';
import {focusOutlineStyles} from '../utils/focusOutline.stylex';
+import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
import {stableClassName} from '../naming';
import {groupStyles} from '../InputGroup/groupStyles';
import {useInputGroup} from '../InputGroup/InputGroupContext';
@@ -195,13 +196,6 @@ const styles = stylex.create({
width: 'auto',
borderWidth: 0,
backgroundColor: 'transparent',
- backgroundImage: {
- default: null,
- ':hover:where(:not(:disabled,[aria-disabled="true"]))': {
- '@media (hover: hover)': `linear-gradient(${colorVars['--color-overlay-hover']}, ${colorVars['--color-overlay-hover']})`,
- },
- ':active': `linear-gradient(${colorVars['--color-overlay-pressed']}, ${colorVars['--color-overlay-pressed']})`,
- },
boxShadow: {
default: 'none',
':hover:not(:focus-within):where(:not(:disabled,[aria-disabled="true"]))':
@@ -1638,6 +1632,7 @@ export function MultiSelector<T extends MultiSelectorOptionType>({
styles.triggerContainer,
sizeStyles[size],
variant === 'ghost' && styles.triggerGhost,
+ variant === 'ghost' && interactionOverlayStyles.backgroundImage,
variant === 'ghost' && focusOutlineStyles.focusWithin,
isDisabled && inputWrapperStyles.disabled,
variant === 'ghost' && isDisabled && styles.triggerGhostDisabled,
diff --git a/packages/core/src/NavItem/navItemStyles.stylex.ts b/packages/core/src/NavItem/navItemStyles.stylex.ts
index 6e88e55852..d1a8c73569 100644
--- a/packages/core/src/NavItem/navItemStyles.stylex.ts
+++ b/packages/core/src/NavItem/navItemStyles.stylex.ts
@@ -75,14 +75,6 @@ export const navItemStyles = stylex.create({
lineHeight: typeScaleVars['--text-label-leading'],
textAlign: 'start',
boxSizing: 'border-box',
- ':hover:where(:not(:disabled,[aria-disabled="true"]))': {
- '@media (hover: hover)': {
- backgroundColor: colorVars['--color-overlay-hover'],
- },
- },
- ':active': {
- backgroundColor: colorVars['--color-overlay-pressed'],
- },
},
/** Selected/active page indicator — deemphasized background, medium weight */
diff --git a/packages/core/src/NumberInput/NumberInput.tsx b/packages/core/src/NumberInput/NumberInput.tsx
index e8c3cd6a97..be976c59bc 100644
--- a/packages/core/src/NumberInput/NumberInput.tsx
+++ b/packages/core/src/NumberInput/NumberInput.tsx
@@ -51,6 +51,7 @@ import {Icon, renderIconSlot, type IconType} from '../Icon';
import {VisuallyHidden} from '../VisuallyHidden';
import {useTooltip} from '../Tooltip';
import {getInputARIA} from '../utils';
+import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
import {useSize} from '../SizeContext/SizeContext';
import {useInputContainer} from '../hooks/useInputContainer';
import {useInputStatusIcon} from '../hooks/useInputStatusIcon';
@@ -161,13 +162,6 @@ const styles = stylex.create({
borderStyle: 'none',
color: colorVars['--color-icon-secondary'],
backgroundColor: colorVars['--color-background-surface'],
- backgroundImage: {
- default: null,
- ':hover:where(:not(:disabled,[aria-disabled="true"]))': {
- '@media (hover: hover)': `linear-gradient(${colorVars['--color-overlay-hover']}, ${colorVars['--color-overlay-hover']})`,
- },
- ':active': `linear-gradient(${colorVars['--color-overlay-pressed']}, ${colorVars['--color-overlay-pressed']})`,
- },
cursor: {
default: 'pointer',
':is(:disabled,[aria-disabled="true"])': 'default',
@@ -970,6 +964,7 @@ export function NumberInput({
}}
{...stylex.props(
styles.numberStepperButton,
+ interactionOverlayStyles.backgroundImage,
(isDisabled || isReadOnly || !canIncrement) &&
styles.numberStepperButtonDisabled,
)}>
@@ -992,6 +987,7 @@ export function NumberInput({
}}
{...stylex.props(
styles.numberStepperButton,
+ interactionOverlayStyles.backgroundImage,
styles.decrementButton,
(isDisabled || isReadOnly || !canDecrement) &&
styles.numberStepperButtonDisabled,
diff --git a/packages/core/src/Outline/Outline.tsx b/packages/core/src/Outline/Outline.tsx
index 7596abce1e..280d236d71 100644
--- a/packages/core/src/Outline/Outline.tsx
+++ b/packages/core/src/Outline/Outline.tsx
@@ -43,6 +43,7 @@ import {useScrollSpy} from './useScrollSpy';
import type {OutlineItem} from './types';
import {themeProps} from '../utils/themeProps';
import {focusOutlineProps} from '../utils/focusOutline.stylex';
+import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
import {useTranslator} from '../i18n';
import {useMergedRefs} from '../hooks/useMergedRefs';
@@ -209,13 +210,9 @@ const styles = stylex.create({
lineHeight: typeScaleVars['--text-body-leading'],
':hover:where(:not(:disabled,[aria-disabled="true"]))': {
'@media (hover: hover)': {
- backgroundColor: colorVars['--color-overlay-hover'],
color: colorVars['--color-text-primary'],
},
},
- ':active': {
- backgroundColor: colorVars['--color-overlay-pressed'],
- },
},
activeLink: {
color: colorVars['--color-text-primary'],
@@ -476,6 +473,7 @@ export function Outline({
}),
focusOutlineProps.focusVisible(
styles.link,
+ interactionOverlayStyles.backgroundColor,
densityStyles[density],
getIndentStyle(item.level),
isActive && styles.activeLink,
diff --git a/packages/core/src/Selector/Selector.tsx b/packages/core/src/Selector/Selector.tsx
index e1f6a789b2..c8df8997cd 100644
--- a/packages/core/src/Selector/Selector.tsx
+++ b/packages/core/src/Selector/Selector.tsx
@@ -80,6 +80,7 @@ import type {BaseProps} from '../BaseProps';
import type {SizeValue} from '../utils/types';
import {themeProps} from '../utils/themeProps';
import {focusOutlineStyles} from '../utils/focusOutline.stylex';
+import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
import {stableClassName} from '../naming';
import {groupStyles} from '../InputGroup/groupStyles';
import {useInputGroup} from '../InputGroup/InputGroupContext';
@@ -217,13 +218,6 @@ const styles = stylex.create({
width: 'auto',
borderWidth: 0,
backgroundColor: 'transparent',
- backgroundImage: {
- default: null,
- ':hover:where(:not(:disabled,[aria-disabled="true"]))': {
- '@media (hover: hover)': `linear-gradient(${colorVars['--color-overlay-hover']}, ${colorVars['--color-overlay-hover']})`,
- },
- ':active': `linear-gradient(${colorVars['--color-overlay-pressed']}, ${colorVars['--color-overlay-pressed']})`,
- },
boxShadow: {
default: 'none',
':hover:not(:focus-within):where(:not(:disabled,[aria-disabled="true"]))':
@@ -1585,6 +1579,7 @@ export function Selector<T extends SelectorOptionType>(
styles.triggerContainer,
sizeStyles[size],
variant === 'ghost' && styles.triggerGhost,
+ variant === 'ghost' && interactionOverlayStyles.backgroundImage,
variant === 'ghost' && focusOutlineStyles.focusWithin,
isDisabled && inputWrapperStyles.disabled,
variant === 'ghost' && isDisabled && styles.triggerGhostDisabled,
diff --git a/packages/core/src/SideNav/SideNavHeading.tsx b/packages/core/src/SideNav/SideNavHeading.tsx
index 0692943541..37acd8ec13 100644
--- a/packages/core/src/SideNav/SideNavHeading.tsx
+++ b/packages/core/src/SideNav/SideNavHeading.tsx
@@ -37,6 +37,7 @@ import {Icon} from '../Icon';
import {Tooltip} from '../Tooltip';
import {navItemStyles} from '../NavItem/navItemStyles.stylex';
import {focusOutlineProps} from '../utils/focusOutline.stylex';
+import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
import {useSideNavCollapse} from './SideNavCollapseContext';
import {useLinkComponent} from '../Link/useLinkComponent';
import type {LinkComponentType} from '../Link/types';
@@ -433,6 +434,7 @@ export function SideNavHeading({
themeProps('side-nav-heading'),
focusOutlineProps.focusVisible(
navItemStyles.item,
+ interactionOverlayStyles.backgroundColor,
styles.rootCollapsed,
xstyle,
),
@@ -456,6 +458,7 @@ export function SideNavHeading({
themeProps('side-nav-heading'),
focusOutlineProps.focusVisible(
navItemStyles.item,
+ interactionOverlayStyles.backgroundColor,
styles.rootCollapsed,
styles.menuTrigger,
xstyle,
diff --git a/packages/core/src/SideNav/SideNavItem.tsx b/packages/core/src/SideNav/SideNavItem.tsx
index a05ba4ebb1..f1504cb08b 100644
--- a/packages/core/src/SideNav/SideNavItem.tsx
+++ b/packages/core/src/SideNav/SideNavItem.tsx
@@ -52,6 +52,7 @@ import type {BaseProps} from '../BaseProps';
import {Tooltip} from '../Tooltip';
import {navItemStyles, type NavItemSize} from '../NavItem/navItemStyles.stylex';
import {focusOutlineProps} from '../utils/focusOutline.stylex';
+import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
import {
useSideNavCollapse,
SideNavCollapseContext,
@@ -151,14 +152,6 @@ const styles = stylex.create({
':is(:disabled,[aria-disabled="true"])': 'default',
},
borderRadius: radiusVars['--radius-element'],
- ':hover:where(:not(:disabled,[aria-disabled="true"]))': {
- '@media (hover: hover)': {
- backgroundColor: colorVars['--color-overlay-hover'],
- },
- },
- ':active': {
- backgroundColor: colorVars['--color-overlay-pressed'],
- },
},
// Primary action element inside the split-action row (link or button).
// Flex:1 so it fills remaining space, giving a wide click target.
@@ -512,6 +505,7 @@ export function SideNavItem({
}),
focusOutlineProps.focusVisible(
navItemStyles.item,
+ interactionOverlayStyles.backgroundColor,
navItemStyles[size],
styles.itemCollapsed,
size === 'sm' && styles.itemCollapsedSm,
@@ -617,6 +611,7 @@ export function SideNavItem({
const itemStyleArgs = [
navItemStyles.item,
+ interactionOverlayStyles.backgroundColor,
navItemStyles[size],
isSelected && navItemStyles.selected,
isDisabled && navItemStyles.disabled,
@@ -662,7 +657,10 @@ export function SideNavItem({
}
aria-expanded={!isItemCollapsed}
aria-controls={`${id}-children`}
- {...focusOutlineProps.focusVisible(styles.expandToggle)}>
+ {...focusOutlineProps.focusVisible(
+ styles.expandToggle,
+ interactionOverlayStyles.backgroundColor,
+ )}>
<Icon
icon="chevronDown"
size="lg"
diff --git a/packages/core/src/Stepper/Step.tsx b/packages/core/src/Stepper/Step.tsx
index d74dc74f5a..3d006f77e3 100644
--- a/packages/core/src/Stepper/Step.tsx
+++ b/packages/core/src/Stepper/Step.tsx
@@ -51,6 +51,7 @@ import {
isRenderable,
themeProps,
} from '../utils';
+import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
import type {BaseProps} from '../BaseProps';
import {Icon} from '../Icon';
import {VisuallyHidden} from '../VisuallyHidden';
@@ -655,13 +656,7 @@ const styles = stylex.create({
'@media (prefers-reduced-motion: reduce)': '0s',
},
transitionTimingFunction: easeVars['--ease-standard'],
- backgroundColor: {
- default: 'transparent',
- ':hover:where(:not(:disabled,[aria-disabled="true"]))': {
- '@media (hover: hover)': colorVars['--color-overlay-hover'],
- },
- ':active': colorVars['--color-overlay-pressed'],
- },
+ backgroundColor: 'transparent',
},
// ===================== ON-TRACK LAYOUT =====================
@@ -702,13 +697,7 @@ const styles = stylex.create({
'@media (prefers-reduced-motion: reduce)': '0s',
},
transitionTimingFunction: easeVars['--ease-standard'],
- backgroundColor: {
- default: 'transparent',
- ':hover:where(:not(:disabled,[aria-disabled="true"]))': {
- '@media (hover: hover)': colorVars['--color-overlay-hover'],
- },
- ':active': colorVars['--color-overlay-pressed'],
- },
+ backgroundColor: 'transparent',
},
otRowWrap: {
@@ -1411,6 +1400,7 @@ export function Step({
aria-label={stepAriaLabel}
{...stylex.props(
styles.otInteractive,
+ interactionOverlayStyles.backgroundColor,
styles.otRowWrap,
styles.otRowPadV(densitySpace),
focusOutlineStyles.focusVisible,
@@ -1493,6 +1483,7 @@ export function Step({
aria-label={stepAriaLabel}
{...stylex.props(
styles.otInteractive,
+ interactionOverlayStyles.backgroundColor,
styles.otColWrap,
styles.otPadBlock(densitySpace),
focusOutlineStyles.focusVisible,
@@ -1549,6 +1540,7 @@ export function Step({
aria-label={stepAriaLabel}
{...stylex.props(
styles.buttonReset,
+ interactionOverlayStyles.backgroundColor,
focusOutlineStyles.focusVisible,
density === 'compact' && styles.densityCompact,
density === 'balanced' && styles.densityBalanced,
@@ -1609,6 +1601,7 @@ export function Step({
aria-label={stepAriaLabel}
{...stylex.props(
styles.buttonReset,
+ interactionOverlayStyles.backgroundColor,
focusOutlineStyles.focusVisible,
density === 'compact' && styles.densityCompact,
density === 'balanced' && styles.densityBalanced,
diff --git a/packages/core/src/Token/Token.tsx b/packages/core/src/Token/Token.tsx
index bdb3419d01..56b7bbcb21 100644
--- a/packages/core/src/Token/Token.tsx
+++ b/packages/core/src/Token/Token.tsx
@@ -37,6 +37,7 @@ import {TokenLink} from './TokenLink';
import type {BaseProps} from '../BaseProps';
import {themeProps} from '../utils/themeProps';
import {focusOutlineProps} from '../utils/focusOutline.stylex';
+import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
import {useTranslator} from '../i18n';
import type {TokenColorMap} from './index';
@@ -143,13 +144,6 @@ const styles = stylex.create({
transitionProperty: 'background-image',
transitionDuration: durationVars['--duration-fast'],
transitionTimingFunction: easeVars['--ease-standard'],
- backgroundImage: {
- default: null,
- ':hover:where(:not(:disabled,[aria-disabled="true"]))': {
- '@media (hover: hover)': `linear-gradient(${colorVars['--color-overlay-hover']}, ${colorVars['--color-overlay-hover']})`,
- },
- ':active': `linear-gradient(${colorVars['--color-overlay-pressed']}, ${colorVars['--color-overlay-pressed']})`,
- },
},
disabled: {
cursor: 'default',
@@ -362,6 +356,7 @@ export function Token({
sizeStyles[size],
colorStyles[color],
styles.interactive,
+ interactionOverlayStyles.backgroundImage,
isDisabled && styles.disabled,
xstyle,
),
@@ -409,6 +404,7 @@ export function Token({
sizeStyles[size],
colorStyles[color],
styles.interactive,
+ interactionOverlayStyles.backgroundImage,
isDisabled && styles.disabled,
xstyle,
),
@@ -441,6 +437,7 @@ export function Token({
sizeStyles[size],
colorStyles[color],
styles.interactive,
+ interactionOverlayStyles.backgroundImage,
isDisabled && styles.disabled,
xstyle,
),
diff --git a/packages/core/src/TopNav/TopNavItem.tsx b/packages/core/src/TopNav/TopNavItem.tsx
index b39af01d63..09111856d6 100644
--- a/packages/core/src/TopNav/TopNavItem.tsx
+++ b/packages/core/src/TopNav/TopNavItem.tsx
@@ -36,6 +36,7 @@ import {mergeProps} from '../utils';
import {useAppShellMobile} from '../AppShell/AppShellMobileContext';
import {themeProps} from '../utils/themeProps';
import {focusOutlineProps} from '../utils/focusOutline.stylex';
+import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
/**
* NavItem styles with hover/selected states
@@ -60,13 +61,6 @@ const styles = stylex.create({
transitionProperty: 'background-color, color',
transitionDuration: durationVars['--duration-fast'],
transitionTimingFunction: easeVars['--ease-standard'],
- backgroundColor: {
- default: 'transparent',
- ':hover:where(:not(:disabled,[aria-disabled="true"]))': {
- '@media (hover: hover)': colorVars['--color-overlay-hover'],
- },
- ':active': colorVars['--color-overlay-pressed'],
- },
},
selected: {
color: colorVars['--color-text-primary'],
@@ -234,6 +228,7 @@ export function TopNavItem({
}),
focusOutlineProps.focusVisible(
navItemStyles.item,
+ interactionOverlayStyles.backgroundColor,
navItemStyles[size],
isSelected && navItemStyles.selected,
isDisabled && navItemStyles.disabled,
@@ -270,6 +265,7 @@ export function TopNavItem({
}),
focusOutlineProps.focusVisible(
styles.base,
+ interactionOverlayStyles.backgroundColor,
isSelected && styles.selected,
isDisabled && navItemStyles.disabled,
isIconOnly && styles.iconOnly,
diff --git a/packages/core/src/TopNav/TopNavMegaMenu.tsx b/packages/core/src/TopNav/TopNavMegaMenu.tsx
index 8bb6dfbcbd..6fe49bd59d 100644
--- a/packages/core/src/TopNav/TopNavMegaMenu.tsx
+++ b/packages/core/src/TopNav/TopNavMegaMenu.tsx
@@ -60,6 +60,7 @@ import {useTopNavSlot} from './TopNavContext';
import {useTopNavRenderMode} from './TopNavRenderContext';
import {themeProps} from '../utils/themeProps';
import {focusOutlineProps} from '../utils/focusOutline.stylex';
+import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
import {useMergedRefs} from '../hooks/useMergedRefs';
// =============================================================================
@@ -567,6 +568,7 @@ function DrawerMegaMenu({
themeProps('top-nav-mega-menu', {mode: 'drawer'}),
focusOutlineProps.focusVisible(
navItemStyles.item,
+ interactionOverlayStyles.backgroundColor,
styles.drawerHeader,
xstyle,
),
diff --git a/packages/core/src/TopNav/TopNavMegaMenuItem.tsx b/packages/core/src/TopNav/TopNavMegaMenuItem.tsx
index 7a851381b7..337597dd86 100644
--- a/packages/core/src/TopNav/TopNavMegaMenuItem.tsx
+++ b/packages/core/src/TopNav/TopNavMegaMenuItem.tsx
@@ -35,6 +35,7 @@ import type {BaseProps} from '../BaseProps';
import {useAppShellMobile} from '../AppShell/AppShellMobileContext';
import {themeProps} from '../utils/themeProps';
import {focusOutlineProps} from '../utils/focusOutline.stylex';
+import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
// =============================================================================
// Styles
@@ -57,13 +58,6 @@ const styles = stylex.create({
transitionProperty: 'background-color',
transitionDuration: durationVars['--duration-fast'],
transitionTimingFunction: easeVars['--ease-standard'],
- backgroundColor: {
- default: 'transparent',
- ':hover:where(:not(:disabled,[aria-disabled="true"]))': {
- '@media (hover: hover)': colorVars['--color-overlay-hover'],
- },
- ':active': colorVars['--color-overlay-pressed'],
- },
border: 'none',
color: 'inherit',
fontFamily: 'inherit',
@@ -218,7 +212,11 @@ export function TopNavMegaMenuItem({
{...elementProps}
{...mergeProps(
themeProps('top-nav-mega-menu-item', {mode: 'drawer'}),
- focusOutlineProps.focusVisible(navItemStyles.item, styles.drawerItem),
+ focusOutlineProps.focusVisible(
+ navItemStyles.item,
+ interactionOverlayStyles.backgroundColor,
+ styles.drawerItem,
+ ),
)}>
{icon && <div {...stylex.props(styles.drawerItemIcon)}>{icon}</div>}
<div {...stylex.props(styles.drawerItemContent)}>
@@ -245,7 +243,10 @@ export function TopNavMegaMenuItem({
tabIndex={tabIndex}
{...mergeProps(
themeProps('top-nav-mega-menu-item'),
- focusOutlineProps.focusVisible(styles.desktop),
+ focusOutlineProps.focusVisible(
+ styles.desktop,
+ interactionOverlayStyles.backgroundColor,
+ ),
)}>
{icon && <div {...stylex.props(styles.desktopIcon)}>{icon}</div>}
<div {...stylex.props(styles.desktopContent)}>
diff --git a/packages/core/src/TopNav/TopNavMenu.tsx b/packages/core/src/TopNav/TopNavMenu.tsx
index ff393631b8..2f5febe54b 100644
--- a/packages/core/src/TopNav/TopNavMenu.tsx
+++ b/packages/core/src/TopNav/TopNavMenu.tsx
@@ -39,6 +39,7 @@ import {useAppShellMobile} from '../AppShell/AppShellMobileContext';
import {useLinkComponent} from '../Link/useLinkComponent';
import {themeProps} from '../utils/themeProps';
import {focusOutlineProps} from '../utils/focusOutline.stylex';
+import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
import {
colorVars,
spacingVars,
@@ -458,6 +459,7 @@ export function TopNavMenu({
{...mergeProps(
focusOutlineProps.focusVisible(
navItemStyles.item,
+ interactionOverlayStyles.backgroundColor,
drawerStyles.header,
xstyle,
),
@@ -492,6 +494,7 @@ export function TopNavMenu({
}}
{...focusOutlineProps.focusVisible(
navItemStyles.item,
+ interactionOverlayStyles.backgroundColor,
drawerStyles.item,
)}>
{item.icon && (
diff --git a/packages/core/src/TreeList/TreeListItem.tsx b/packages/core/src/TreeList/TreeListItem.tsx
index f47593e0af..166fcb66d6 100644
--- a/packages/core/src/TreeList/TreeListItem.tsx
+++ b/packages/core/src/TreeList/TreeListItem.tsx
@@ -25,6 +25,7 @@ import {
typeScaleVars,
} from '../theme/tokens.stylex';
import {focusOutlineProps} from '../utils/focusOutline.stylex';
+import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
import {Icon} from '../Icon';
import {mergeProps} from '../utils';
import {useLinkComponent} from '../Link/useLinkComponent';
@@ -102,13 +103,6 @@ const styles = stylex.create({
transitionProperty: 'background-image',
transitionDuration: durationVars['--duration-fast'],
transitionTimingFunction: easeVars['--ease-standard'],
- backgroundImage: {
- default: null,
- ':hover:where(:not(:disabled,[aria-disabled="true"]))': {
- '@media (hover: hover)': `linear-gradient(${colorVars['--color-overlay-hover']}, ${colorVars['--color-overlay-hover']})`,
- },
- ':active': `linear-gradient(${colorVars['--color-overlay-pressed']}, ${colorVars['--color-overlay-pressed']})`,
- },
},
disabled: {
cursor: 'default',
@@ -592,6 +586,7 @@ export function TreeListItem({
styles.contentWrapper,
densityStyles[density],
styles.interactive,
+ interactionOverlayStyles.backgroundImage,
isDisabled && styles.disabled,
isSelected && styles.selected,
)
diff --git a/packages/core/src/utils/interactionOverlay.stylex.ts b/packages/core/src/utils/interactionOverlay.stylex.ts
new file mode 100644
index 0000000000..740054b7ad
--- /dev/null
+++ b/packages/core/src/utils/interactionOverlay.stylex.ts
@@ -0,0 +1,74 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/* eslint-disable @astryx/no-hover-on-disabled -- Every hover branch is
+ * nested beneath ENABLED below. Keeping that shared guard outside the media
+ * branch is what gives hover and active matching generated specificity. */
+
+/**
+ * @file Shared hover and pressed overlay states
+ * @input Uses StyleX and the semantic interaction-overlay color tokens
+ * @output Exports reusable background-color and background-image state styles
+ * @position Internal styling utility for interactive core surfaces
+ *
+ * Keep the enabled guard outside the individual states. StyleX assigns an
+ * extra priority bucket (and generated selector specificity) to media-nested
+ * rules. Repeating `:active` inside the hover-capable branch gives hover and
+ * press the same generated specificity; StyleX's native pseudo-state ordering
+ * then emits `:active` last. The bare `:active` branch remains the touch
+ * fallback, where `(hover: hover)` does not match.
+ */
+
+import * as stylex from '@stylexjs/stylex';
+import {colorVars} from '../theme/tokens.stylex';
+
+const ENABLED = ':where(:not(:disabled,[aria-disabled="true"]))';
+const HOVER_HOVER = '@media (hover: hover)';
+
+const hoverImage = `linear-gradient(${colorVars['--color-overlay-hover']}, ${colorVars['--color-overlay-hover']})`;
+const pressedImage = `linear-gradient(${colorVars['--color-overlay-pressed']}, ${colorVars['--color-overlay-pressed']})`;
+const neutralImage = `linear-gradient(${colorVars['--color-neutral']}, ${colorVars['--color-neutral']})`;
+
+export const interactionOverlayStyles = stylex.create({
+ backgroundColor: {
+ backgroundColor: {
+ default: 'transparent',
+ [ENABLED]: {
+ default: null,
+ ':active': colorVars['--color-overlay-pressed'],
+ [HOVER_HOVER]: {
+ default: null,
+ ':hover': colorVars['--color-overlay-hover'],
+ ':active': colorVars['--color-overlay-pressed'],
+ },
+ },
+ },
+ },
+ backgroundImage: {
+ backgroundImage: {
+ default: null,
+ [ENABLED]: {
+ default: null,
+ ':active': pressedImage,
+ [HOVER_HOVER]: {
+ default: null,
+ ':hover': hoverImage,
+ ':active': pressedImage,
+ },
+ },
+ },
+ },
+ backgroundImageOnNeutral: {
+ backgroundImage: {
+ default: neutralImage,
+ [ENABLED]: {
+ default: null,
+ ':active': `${pressedImage}, ${neutralImage}`,
+ [HOVER_HOVER]: {
+ default: null,
+ ':hover': `${hoverImage}, ${neutralImage}`,
+ ':active': `${pressedImage}, ${neutralImage}`,
+ },
+ },
+ },
+ },
+});
diff --git a/scripts/build-css.test.mjs b/scripts/build-css.test.mjs
index 9abb7d980d..945b5b2578 100644
--- a/scripts/build-css.test.mjs
+++ b/scripts/build-css.test.mjs
@@ -45,6 +45,58 @@ function extractMediaRules(css) {
return rules;
}
+/** Remove one functional pseudo-class, including nested parentheses. */
+function removeFunctionalPseudo(selector, name) {
+ let result = selector;
+ const needle = `:${name}(`;
+ for (;;) {
+ const start = result.indexOf(needle);
+ if (start === -1) return result;
+ let depth = 1;
+ let end = start + needle.length;
+ while (end < result.length && depth > 0) {
+ if (result[end] === '(') depth++;
+ else if (result[end] === ')') depth--;
+ end++;
+ }
+ result = result.slice(0, start) + result.slice(end);
+ }
+}
+
+/** Specificity tuple for the generated selectors used by the state guard. */
+function specificity(selector) {
+ const withoutWhere = removeFunctionalPseudo(selector, 'where');
+ const ids = (withoutWhere.match(/#/g) ?? []).length;
+ const classes = (withoutWhere.match(/\.[a-zA-Z0-9_-]+/g) ?? []).length;
+ const attributes = (withoutWhere.match(/\[[^\]]+\]/g) ?? []).length;
+ const pseudos = (
+ withoutWhere.match(/:(?!:|not\(|is\(|has\()[a-zA-Z-]+/g) ?? []
+ ).length;
+ return [ids, classes + attributes + pseudos, 0];
+}
+
+function stateRule(css, {property, token, state, media}) {
+ const lines = css.split('\n');
+ return lines.find(line => {
+ const inHoverMedia = line.includes('@media (hover: hover)');
+ return (
+ inHoverMedia === media &&
+ line.includes(`:${state}:where(`) &&
+ !line.includes('::') &&
+ line.includes(`${property}:`) &&
+ line.includes(`var(--color-overlay-${token})`)
+ );
+ });
+}
+
+function selectorFromRule(rule) {
+ const declaration = rule.lastIndexOf('{');
+ const mediaBody = rule.indexOf('{');
+ return rule
+ .slice(rule.includes('@media') ? mediaBody + 1 : 0, declaration)
+ .trim();
+}
+
describe('build-css astryx.css', () => {
let astryxCss;
@@ -71,9 +123,52 @@ describe('build-css astryx.css', () => {
r.includes('prefers-reduced-motion'),
);
expect(motionRules.length).toBeGreaterThan(0);
- console.log(`astryx.css has ${motionRules.length} prefers-reduced-motion rules`);
+ console.log(
+ `astryx.css has ${motionRules.length} prefers-reduced-motion rules`,
+ );
});
+ it.each(['background-color', 'background-image'])(
+ 'emits %s pressed after hover at equal specificity',
+ property => {
+ const hover = stateRule(astryxCss, {
+ property,
+ token: 'hover',
+ state: 'hover',
+ media: true,
+ });
+ const pressed = stateRule(astryxCss, {
+ property,
+ token: 'pressed',
+ state: 'active',
+ media: true,
+ });
+
+ expect(hover).toBeDefined();
+ expect(pressed).toBeDefined();
+ expect(specificity(selectorFromRule(pressed))).toEqual(
+ specificity(selectorFromRule(hover)),
+ );
+ expect(astryxCss.indexOf(pressed)).toBeGreaterThan(
+ astryxCss.indexOf(hover),
+ );
+ },
+ );
+
+ it.each(['background-color', 'background-image'])(
+ 'keeps the bare %s pressed rule for touch input',
+ property => {
+ expect(
+ stateRule(astryxCss, {
+ property,
+ token: 'pressed',
+ state: 'active',
+ media: false,
+ }),
+ ).toBeDefined();
+ },
+ );
+
it('no transition-duration:0s rules appear outside @media blocks', () => {
const zeroTransitionRegex =
/\.[a-z][a-z0-9_-]+[^{}]*\{[^}]*transition-duration:\s*0s[^}]*\}/g;
@@ -112,7 +207,10 @@ describe('build-css astryx.css', () => {
it('does not produce per-component CSS files', async () => {
// Verify the cleanup — no common.css or per-component styles.css
await expect(
- fs.access(path.join(CORE_DIST, 'common.css')).then(() => true, () => false),
+ fs.access(path.join(CORE_DIST, 'common.css')).then(
+ () => true,
+ () => false,
+ ),
).resolves.toBe(false);
});
});