An open source design system that's fully customizable and agent ready
TypeScript
fix(checkbox,radio,switch): scope ancestor selectors with defineMarker (#1258) (#1294)
Cindy Zhangfa4a94bdffc2
diff --git a/CLAUDE.md b/CLAUDE.mdindex 41666e250c..9c083fa9b3 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -111,7 +111,7 @@ Look for `<!-- SYNC: ... -->` comments and `SYNC:` in file headers as reminders.|VARS: stylex.defineVars, stylex.createTheme (require .stylex.ts files) — YES|LAYOUT: grid, flex+gap, aspect-ratio, overscrollBehavior, scrollbar-gutter/width — YES|PATTERN: dialog entry animation -> @starting-style (not useState+rAF)-|PATTERN: parent hover child style -> stylex.when.ancestor(':hover') (not CSS nesting). Ancestor element MUST have stylex.defaultMarker() in its stylex.props() call+|PATTERN: parent hover child style -> stylex.when.ancestor(':hover', marker) (not CSS nesting). Use stylex.defineMarker() in a .stylex.ts file for scoped markers. Ancestor element MUST have marker.marker in its stylex.props() call. NEVER use stylex.defaultMarker() for form controls (CheckboxInput, RadioList, Switch) — it leaks hover/focus-within from outer containers like Popovers. Always use a component-scoped defineMarker() instead.|PATTERN: hover on touch -> @media (hover: hover) guard|PATTERN: zebra striping -> :nth-child(even) (not index%2 JS)|PATTERN: container responsive -> @container (not ResizeObserver)@@ -127,19 +127,19 @@ Look for `<!-- SYNC: ... -->` comments and `SYNC:` in file headers as reminders.XDS CLI|Run from repo root. Load agent docs before any component work.XDS="node packages/cli/bin/xds.mjs"BOOTSTRAP (run every branch, <500ms):- $XDS help # discover all commands and options- $XDS docs # list available doc topics- $XDS docs principles --dense # design rules, anti-patterns, xstyle, tokens- $XDS docs tokens --dense # spacing, color, radius, typography, shadow- $XDS docs theme --dense # theme provider, light/dark, overrides- $XDS component --list # all components grouped by category- $XDS template --list # available page templates+$XDS help # discover all commands and options+$XDS docs # list available doc topics+$XDS docs principles --dense # design rules, anti-patterns, xstyle, tokens+$XDS docs tokens --dense # spacing, color, radius, typography, shadow+$XDS docs theme --dense # theme provider, light/dark, overrides+$XDS component --list # all components grouped by category+$XDS template --list # available page templatesON DEMAND:- $XDS component <Name> --dense # props, variants, usage, anatomy for one component- $XDS template <name> # emit full page source- $XDS template <name> --skeleton # layout skeleton with spatial annotations- $XDS swizzle <Name> # eject component source (use --gap to report why)- $XDS upgrade --apply # run version migration codemods+$XDS component <Name> --dense # props, variants, usage, anatomy for one component+$XDS template <name> # emit full page source+$XDS template <name> --skeleton # layout skeleton with spatial annotations+$XDS swizzle <Name> # eject component source (use --gap to report why)+$XDS upgrade --apply # run version migration codemodsOPTIONS: --detail compact|brief less output | --dense token-efficient | --zh ChineseRULE: always run bootstrap on each branch — docs reflect the branch's actual APIRULE: always run $XDS component <Name> --dense before modifying a componentdiff --git a/packages/core/src/CheckboxInput/XDSCheckboxInput.tsx b/packages/core/src/CheckboxInput/XDSCheckboxInput.tsxindex f5cce85b8e..9358029a55 100644--- a/packages/core/src/CheckboxInput/XDSCheckboxInput.tsx+++ b/packages/core/src/CheckboxInput/XDSCheckboxInput.tsx@@ -40,6 +40,7 @@ import type {XDSIconType} from '../Icon';import type {XDSInputStatus} from '../Field/types';import {XDSSpinner} from '../Spinner';import {xdsClassName, mergeProps} from '../utils';+import {checkboxScope} from './checkbox.markers.stylex';const styles = stylex.create({container: {@@ -85,25 +86,25 @@ const styles = stylex.create({checkboxFocus: {outline: {default: 'none',- [stylex.when.ancestor(':focus-within')]:+ [stylex.when.ancestor(':focus-within', checkboxScope)]:`2px solid ${colorVars['--color-accent']}`,},outlineOffset: {default: null,- [stylex.when.ancestor(':focus-within')]: '2px',+ [stylex.when.ancestor(':focus-within', checkboxScope)]: '2px',},},// State-dependent colors with ancestor hover behaviorcheckboxUnchecked: {borderColor: {default: colorVars['--color-border-emphasized'],- [stylex.when.ancestor(':hover')]: {+ [stylex.when.ancestor(':hover', checkboxScope)]: {'@media (hover: hover)': `color-mix(in srgb, ${colorVars['--color-border-emphasized']}, ${colorVars['--color-tint-hover']} 20%)`,},},backgroundColor: {default: colorVars['--color-background-surface'],- [stylex.when.ancestor(':hover')]: {+ [stylex.when.ancestor(':hover', checkboxScope)]: {'@media (hover: hover)': `color-mix(in srgb, ${colorVars['--color-background-surface']}, ${colorVars['--color-tint-hover']} 5%)`,},},@@ -111,13 +112,13 @@ const styles = stylex.create({checkboxChecked: {borderColor: {default: colorVars['--color-accent'],- [stylex.when.ancestor(':hover')]: {+ [stylex.when.ancestor(':hover', checkboxScope)]: {'@media (hover: hover)': `color-mix(in srgb, ${colorVars['--color-accent']}, ${colorVars['--color-tint-hover']} 15%)`,},},backgroundColor: {default: colorVars['--color-accent'],- [stylex.when.ancestor(':hover')]: {+ [stylex.when.ancestor(':hover', checkboxScope)]: {'@media (hover: hover)': `color-mix(in srgb, ${colorVars['--color-accent']}, ${colorVars['--color-tint-hover']} 15%)`,},},@@ -126,7 +127,7 @@ const styles = stylex.create({opacity: 0.5,borderColor: {default: colorVars['--color-border'],- [stylex.when.ancestor(':hover')]: {+ [stylex.when.ancestor(':hover', checkboxScope)]: {'@media (hover: hover)': colorVars['--color-border'],},},@@ -134,7 +135,7 @@ const styles = stylex.create({checkboxDisabledUnchecked: {backgroundColor: {default: colorVars['--color-background-muted'],- [stylex.when.ancestor(':hover')]: {+ [stylex.when.ancestor(':hover', checkboxScope)]: {'@media (hover: hover)': colorVars['--color-background-muted'],},},@@ -380,7 +381,7 @@ export function XDSCheckboxInput({{...stylex.props(styles.container,isLabelHidden && styles.containerLabelHidden,- !isDisabled && stylex.defaultMarker(),+ !isDisabled && checkboxScope,)}><div {...stylex.props(styles.checkboxWrapper, wrapperSizeStyles[size])}><inputdiff --git a/packages/core/src/CheckboxInput/checkbox.markers.stylex.ts b/packages/core/src/CheckboxInput/checkbox.markers.stylex.tsnew file mode 100644index 0000000000..124c0842d6--- /dev/null+++ b/packages/core/src/CheckboxInput/checkbox.markers.stylex.ts@@ -0,0 +1,9 @@+import * as stylex from '@stylexjs/stylex';++/**+ * Scoped marker for CheckboxInput ancestor selectors.+ * Prevents focus-within and hover styles from leaking when+ * checkboxes are placed inside Popovers or other containers+ * that also have focus-within state.+ */+export const checkboxScope = stylex.defineMarker();diff --git a/packages/core/src/RadioList/XDSRadioListItem.tsx b/packages/core/src/RadioList/XDSRadioListItem.tsxindex 88d9f88dc4..6abf2a83ae 100644--- a/packages/core/src/RadioList/XDSRadioListItem.tsx+++ b/packages/core/src/RadioList/XDSRadioListItem.tsx@@ -27,6 +27,7 @@ import {} from '../theme/tokens.stylex';import {XDSRadioListContext} from './XDSRadioList';import {xdsClassName, mergeProps} from '../utils';+import {radioScope} from './radio.markers.stylex';const styles = stylex.create({container: {@@ -67,13 +68,13 @@ const styles = stylex.create({radioUnchecked: {borderColor: {default: colorVars['--color-border-emphasized'],- [stylex.when.ancestor(':hover')]: {+ [stylex.when.ancestor(':hover', radioScope)]: {'@media (hover: hover)': `color-mix(in srgb, ${colorVars['--color-border-emphasized']}, ${colorVars['--color-tint-hover']} 20%)`,},},backgroundColor: {default: colorVars['--color-background-surface'],- [stylex.when.ancestor(':hover')]: {+ [stylex.when.ancestor(':hover', radioScope)]: {'@media (hover: hover)': `color-mix(in srgb, ${colorVars['--color-background-surface']}, ${colorVars['--color-tint-hover']} 5%)`,},},@@ -81,13 +82,13 @@ const styles = stylex.create({radioChecked: {borderColor: {default: colorVars['--color-accent'],- [stylex.when.ancestor(':hover')]: {+ [stylex.when.ancestor(':hover', radioScope)]: {'@media (hover: hover)': `color-mix(in srgb, ${colorVars['--color-accent']}, ${colorVars['--color-tint-hover']} 15%)`,},},backgroundColor: {default: colorVars['--color-accent'],- [stylex.when.ancestor(':hover')]: {+ [stylex.when.ancestor(':hover', radioScope)]: {'@media (hover: hover)': `color-mix(in srgb, ${colorVars['--color-accent']}, ${colorVars['--color-tint-hover']} 15%)`,},},@@ -252,7 +253,7 @@ export function XDSRadioListItem({data-testid={dataTestId}{...mergeProps(xdsClassName('radio-list-item'),- stylex.props(styles.container, !isDisabled && stylex.defaultMarker()),+ stylex.props(styles.container, !isDisabled && radioScope),)}><div{...stylex.props(diff --git a/packages/core/src/RadioList/radio.markers.stylex.ts b/packages/core/src/RadioList/radio.markers.stylex.tsnew file mode 100644index 0000000000..7d29f79ce0--- /dev/null+++ b/packages/core/src/RadioList/radio.markers.stylex.ts@@ -0,0 +1,7 @@+import * as stylex from '@stylexjs/stylex';++/**+ * Scoped marker for RadioListItem ancestor selectors.+ * Prevents hover styles from leaking from parent containers.+ */+export const radioScope = stylex.defineMarker();diff --git a/packages/core/src/Switch/XDSSwitch.tsx b/packages/core/src/Switch/XDSSwitch.tsxindex 6b5745add1..3616ef8619 100644--- a/packages/core/src/Switch/XDSSwitch.tsx+++ b/packages/core/src/Switch/XDSSwitch.tsx@@ -36,6 +36,7 @@ import type {XDSIconType} from '../Icon';import type {XDSInputStatus} from '../Field/types';import {XDSSpinner} from '../Spinner';import {xdsClassName, mergeProps} from '../utils';+import {switchScope} from './switch.markers.stylex';import {XDSBaseProps} from '../XDSBaseProps';// Fixed dimensions: 40px width, 24px height, 16px thumb (off), 20px thumb (on)@@ -105,19 +106,19 @@ const styles = stylex.create({trackFocus: {outline: {default: 'none',- [stylex.when.ancestor(':focus-within')]:+ [stylex.when.ancestor(':focus-within', switchScope)]:`2px solid ${colorVars['--color-accent']}`,},outlineOffset: {default: null,- [stylex.when.ancestor(':focus-within')]: '2px',+ [stylex.when.ancestor(':focus-within', switchScope)]: '2px',},},// State-dependent colors with ancestor hover behaviortrackOff: {backgroundColor: {default: colorVars['--color-background-gray'],- [stylex.when.ancestor(':hover')]: {+ [stylex.when.ancestor(':hover', switchScope)]: {'@media (hover: hover)': `color-mix(in srgb, ${colorVars['--color-background-gray']}, ${colorVars['--color-tint-hover']} 5%)`,},},@@ -125,7 +126,7 @@ const styles = stylex.create({trackOn: {backgroundColor: {default: colorVars['--color-accent'],- [stylex.when.ancestor(':hover')]: {+ [stylex.when.ancestor(':hover', switchScope)]: {'@media (hover: hover)': `color-mix(in srgb, ${colorVars['--color-accent']}, ${colorVars['--color-tint-hover']} 15%)`,},},@@ -433,8 +434,9 @@ export function XDSSwitch({{...stylex.props(styles.container,labelSpacing === 'spread' && styles.containerSpread,- !isDisabled && stylex.defaultMarker(),+ !isDisabled && switchScope,)}>+ {' '}{labelPosition === 'start' ? (<>{labelElement}diff --git a/packages/core/src/Switch/switch.markers.stylex.ts b/packages/core/src/Switch/switch.markers.stylex.tsnew file mode 100644index 0000000000..ef13806eab--- /dev/null+++ b/packages/core/src/Switch/switch.markers.stylex.ts@@ -0,0 +1,7 @@+import * as stylex from '@stylexjs/stylex';++/**+ * Scoped marker for Switch ancestor selectors.+ * Prevents focus-within and hover styles from leaking from parent containers.+ */+export const switchScope = stylex.defineMarker();