Skip to content

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

TypeScript

feat(selector): add icon theme targets for Selector + MultiSelector (+ Icon styling-prop handling) (#4503)

freddymetaeff3e5f3ed45
diff --git a/.changeset/selector-icon-theme-targets.md b/.changeset/selector-icon-theme-targets.md
new file mode 100644
index 0000000000..90a77444ad
--- /dev/null
+++ b/.changeset/selector-icon-theme-targets.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[feat] Selector & MultiSelector: add `astryx-selector-clear-icon`, `astryx-selector-indicator-icon`, `astryx-multi-selector-clear-icon`, and `astryx-multi-selector-indicator-icon` theme targets on the clear and chevron glyphs, so consumers can recolor, resize, and hover-style each icon — and style the chevron's open/closed state — via `defineTheme` instead of a fragile descendant selector or raw CSS. Each chevron reflects its open/closed state as a `data-state` attribute. `Icon` now fully handles its styling props (`className`, `style`, `xstyle`) so they compose with its base styles instead of being dropped. Default rendering is unchanged.
+
+@freddymeta
diff --git a/apps/storybook/stories/MultiSelector.stories.tsx b/apps/storybook/stories/MultiSelector.stories.tsx
index 52baecc717..7e4c0c503e 100644
--- a/apps/storybook/stories/MultiSelector.stories.tsx
+++ b/apps/storybook/stories/MultiSelector.stories.tsx
@@ -3,6 +3,7 @@
import type {Meta, StoryObj} from '@storybook/react';
import {useState} from 'react';
import {MultiSelector} from '@astryxdesign/core/MultiSelector';
+import {Theme, defineTheme} from '@astryxdesign/core/theme';
const meta: Meta<typeof MultiSelector> = {
title: 'Core/MultiSelector',
@@ -471,3 +472,60 @@ export const StatusVariantComparison: Story = {
},
decorators: [Story => <Story />],
};
+
+/**
+ * Theme the clear and chevron glyphs precisely via `defineTheme`.
+ *
+ * - `components['multi-selector-clear-icon'].base` scopes overrides to the
+ * clear icon itself (via the `astryx-multi-selector-clear-icon` target), so a
+ * theme can recolor it, morph its color on hover, and resize it — without a
+ * fragile descendant selector or raw CSS.
+ * - `components['multi-selector-indicator-icon']` scopes overrides to the
+ * chevron, and its `state:expanded` restyles the open state, which the icon
+ * reflects as a `data-state` attribute.
+ *
+ * Same-element rules in `@layer astryx-theme` win over each icon's own base
+ * color/size.
+ */
+const iconTheme = defineTheme({
+ name: 'multi-selector-icon-demo',
+ components: {
+ 'multi-selector-clear-icon': {
+ base: {
+ width: '12px',
+ height: '12px',
+ fontSize: '12px',
+ color: 'var(--color-icon-secondary)',
+ ':hover': {color: 'var(--color-accent)'},
+ },
+ },
+ 'multi-selector-indicator-icon': {
+ base: {
+ width: '14px',
+ height: '14px',
+ fontSize: '14px',
+ color: 'var(--color-icon-secondary)',
+ },
+ 'state:expanded': {
+ color: 'var(--color-accent)',
+ },
+ },
+ },
+});
+
+export const ThemedIcons: Story = {
+ render: () => {
+ const [value, setValue] = useState<string[]>(['Apple', 'Banana']);
+ return (
+ <Theme theme={iconTheme} mode="light">
+ <MultiSelector
+ label="Icons themed (accent on hover/open)"
+ options={['Apple', 'Banana', 'Orange']}
+ value={value}
+ onChange={setValue}
+ hasClear
+ />
+ </Theme>
+ );
+ },
+};
diff --git a/apps/storybook/stories/Selector.stories.tsx b/apps/storybook/stories/Selector.stories.tsx
index ef7254d257..50930c1d53 100644
--- a/apps/storybook/stories/Selector.stories.tsx
+++ b/apps/storybook/stories/Selector.stories.tsx
@@ -3,6 +3,7 @@
import type {Meta, StoryObj} from '@storybook/react';
import {useState} from 'react';
import {Selector, SelectorOption} from '@astryxdesign/core/Selector';
+import {Theme, defineTheme} from '@astryxdesign/core/theme';
import {UserIcon, CogIcon, BellIcon} from '@heroicons/react/24/outline';
const meta: Meta<typeof Selector> = {
@@ -687,3 +688,60 @@ export const StatusVariantComparison: Story = {
},
decorators: [Story => <Story />],
};
+
+/**
+ * Theme the clear and chevron glyphs precisely via `defineTheme`.
+ *
+ * - `components['selector-clear-icon'].base` scopes overrides to the clear icon
+ * itself (via the `astryx-selector-clear-icon` target), so a theme can
+ * recolor it, morph its color on hover, and resize it — without a fragile
+ * descendant selector or raw CSS.
+ * - `components['selector-indicator-icon']` scopes overrides to the chevron,
+ * and its `state:expanded` restyles the open state, which the icon reflects
+ * as a `data-state` attribute.
+ *
+ * Same-element rules in `@layer astryx-theme` win over each icon's own base
+ * color/size.
+ */
+const iconTheme = defineTheme({
+ name: 'selector-icon-demo',
+ components: {
+ 'selector-clear-icon': {
+ base: {
+ width: '12px',
+ height: '12px',
+ fontSize: '12px',
+ color: 'var(--color-icon-secondary)',
+ ':hover': {color: 'var(--color-accent)'},
+ },
+ },
+ 'selector-indicator-icon': {
+ base: {
+ width: '14px',
+ height: '14px',
+ fontSize: '14px',
+ color: 'var(--color-icon-secondary)',
+ },
+ 'state:expanded': {
+ color: 'var(--color-accent)',
+ },
+ },
+ },
+});
+
+export const ThemedIcons: Story = {
+ render: () => {
+ const [value, setValue] = useState<string | null>('Banana');
+ return (
+ <Theme theme={iconTheme} mode="light">
+ <Selector
+ label="Icons themed (accent on hover/open)"
+ options={['Apple', 'Banana', 'Cherry']}
+ value={value}
+ onChange={setValue}
+ hasClear
+ />
+ </Theme>
+ );
+ },
+};
diff --git a/packages/core/src/MultiSelector/MultiSelector.doc.mjs b/packages/core/src/MultiSelector/MultiSelector.doc.mjs
index e0d5520d9a..d51619e4af 100644
--- a/packages/core/src/MultiSelector/MultiSelector.doc.mjs
+++ b/packages/core/src/MultiSelector/MultiSelector.doc.mjs
@@ -21,6 +21,11 @@ export const docs = {
theming: {
targets: [
{className: 'astryx-multi-selector', visualProps: ['size', 'status']},
+ {className: 'astryx-multi-selector-clear-icon'},
+ {
+ className: 'astryx-multi-selector-indicator-icon',
+ states: ['state'],
+ },
],
},
components: [
diff --git a/packages/core/src/MultiSelector/MultiSelector.test.tsx b/packages/core/src/MultiSelector/MultiSelector.test.tsx
index d192a291ea..e8b78cd8db 100644
--- a/packages/core/src/MultiSelector/MultiSelector.test.tsx
+++ b/packages/core/src/MultiSelector/MultiSelector.test.tsx
@@ -19,7 +19,10 @@ import {
} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import {MultiSelector} from './MultiSelector';
+import {Icon} from '../Icon';
import {__resetLiveRegionsForTest} from '../hooks/useAnnounce';
+import {defineTheme} from '../theme/defineTheme';
+import {generateThemeCSSFlat} from '../theme/generateThemeRules';
// Module-level constants to satisfy @eslint-react/no-unstable-default-props.
const ANNOUNCE_OPTIONS = ['Apple', 'Banana', 'Orange'] as const;
@@ -1312,11 +1315,16 @@ describe('MultiSelector', () => {
});
});
-
describe('MultiSelector statusVariant forwarding', () => {
it('defaults to attached (status renders with data-variant="attached")', () => {
const {container} = render(
- <MultiSelector label="Fruit" options={['Apple', 'Banana']} value={[]} onChange={() => {}} status={{type: 'error', message: 'Required'}} />,
+ <MultiSelector
+ label="Fruit"
+ options={['Apple', 'Banana']}
+ value={[]}
+ onChange={() => {}}
+ status={{type: 'error', message: 'Required'}}
+ />,
);
expect(container.querySelector('.astryx-field-status')).toHaveAttribute(
'data-variant',
@@ -1326,7 +1334,14 @@ describe('MultiSelector statusVariant forwarding', () => {
it('forwards statusVariant="detached" to the underlying Field status', () => {
const {container} = render(
- <MultiSelector label="Fruit" options={['Apple', 'Banana']} value={[]} onChange={() => {}} status={{type: 'error', message: 'Required'}} statusVariant="detached" />,
+ <MultiSelector
+ label="Fruit"
+ options={['Apple', 'Banana']}
+ value={[]}
+ onChange={() => {}}
+ status={{type: 'error', message: 'Required'}}
+ statusVariant="detached"
+ />,
);
expect(container.querySelector('.astryx-field-status')).toHaveAttribute(
'data-variant',
@@ -1334,3 +1349,225 @@ describe('MultiSelector statusVariant forwarding', () => {
);
});
});
+
+describe('MultiSelector clear icon theme target', () => {
+ const ICON_OPTIONS = ['Apple', 'Banana', 'Orange'];
+
+ // Resolve the clear glyph span (the astryx-icon element inside the clear
+ // button), independent of the theme target class.
+ const getClearIcon = (): HTMLElement => {
+ const button = screen.getByRole('button', {name: 'Clear all Fruit'});
+ const icon = button.querySelector('.astryx-icon');
+ if (icon == null) {
+ throw new Error('clear icon not found');
+ }
+ return icon as HTMLElement;
+ };
+
+ it('renders the astryx-multi-selector-clear-icon target on the clear glyph', () => {
+ render(
+ <MultiSelector
+ label="Fruit"
+ options={ICON_OPTIONS}
+ value={['Banana']}
+ onChange={() => {}}
+ hasClear
+ />,
+ );
+ // The stable theme target lands on the icon element itself (not the
+ // button), so a theme can restyle just this glyph (color, size, hover)
+ // via `defineTheme` — a button-level target could not reach the icon's
+ // own color/size.
+ const icon = getClearIcon();
+ expect(icon).toHaveClass('astryx-multi-selector-clear-icon');
+ expect(icon).toHaveClass('astryx-icon');
+ });
+
+ it('keeps the clear button functional alongside the target', () => {
+ const onChange = vi.fn();
+ render(
+ <MultiSelector
+ label="Fruit"
+ options={ICON_OPTIONS}
+ value={['Banana']}
+ onChange={onChange}
+ hasClear
+ />,
+ );
+ const clear = screen.getByRole('button', {name: 'Clear all Fruit'});
+ expect(clear.tagName).toBe('BUTTON');
+ fireEvent.click(clear);
+ expect(onChange).toHaveBeenCalledWith([]);
+ });
+
+ it('renders the default icon (secondary color, sm size) byte-identically', () => {
+ // Pixel-identical default guard: the clear glyph must carry the exact same
+ // StyleX color/size classes as a standalone secondary/sm icon. The added
+ // target class is purely additive — it changes nothing until a theme
+ // targets it.
+ render(
+ <MultiSelector
+ label="Fruit"
+ options={ICON_OPTIONS}
+ value={['Banana']}
+ onChange={() => {}}
+ hasClear
+ />,
+ );
+ const icon = getClearIcon();
+
+ const {container: refContainer} = render(
+ <Icon icon="close" size="sm" color="secondary" />,
+ );
+ const refIcon = refContainer.querySelector('.astryx-icon') as HTMLElement;
+
+ const styleClasses = (el: HTMLElement) =>
+ el.className
+ .split(' ')
+ .filter(c => c !== 'astryx-multi-selector-clear-icon')
+ .sort();
+
+ expect(styleClasses(icon)).toEqual(styleClasses(refIcon));
+ });
+
+ it('exposes multi-selector-clear-icon so a theme reaches the icon color, size, and hover', () => {
+ // jsdom cannot resolve the @layer cascade, so the DOM-class assertion above
+ // (target lands on the icon element) plus this generation assertion (the
+ // theme emits same-element icon rules in @layer astryx-theme) together
+ // prove the seam: a same-element theme rule wins over the icon's own
+ // base-layer color/size.
+ const theme = defineTheme({
+ name: 'multi-selector-clear-icon-test',
+ components: {
+ 'multi-selector-clear-icon': {
+ base: {
+ width: '12px',
+ height: '12px',
+ fontSize: '12px',
+ color: 'var(--color-icon-secondary)',
+ ':hover': {color: 'var(--color-icon-primary)'},
+ },
+ },
+ },
+ });
+ const css = generateThemeCSSFlat(theme);
+ expect(css).toContain('.astryx-multi-selector-clear-icon {');
+ expect(css).toContain('width: 12px');
+ expect(css).toContain('height: 12px');
+ expect(css).toContain('.astryx-multi-selector-clear-icon:hover {');
+ expect(css).toContain('color: var(--color-icon-primary)');
+ });
+});
+
+describe('MultiSelector indicator (chevron) icon theme target', () => {
+ const ICON_OPTIONS = ['Apple', 'Banana', 'Orange'];
+
+ const getIndicatorIcon = (container: HTMLElement): HTMLElement => {
+ // The chevron is the only glyph carrying the indicator target class.
+ const icon = container.querySelector(
+ '.astryx-multi-selector-indicator-icon',
+ );
+ if (icon == null) {
+ throw new Error('indicator icon not found');
+ }
+ return icon as HTMLElement;
+ };
+
+ it('renders the astryx-multi-selector-indicator-icon target on the chevron glyph', () => {
+ const {container} = render(
+ <MultiSelector
+ label="Fruit"
+ options={ICON_OPTIONS}
+ value={[]}
+ onChange={() => {}}
+ />,
+ );
+ // The stable theme target lands on the icon element itself (not the trigger
+ // button), so a theme can restyle just this glyph (color, size, hover) —
+ // and each open/closed state — via `defineTheme`. A button-level target
+ // could not reach the icon's own color/size.
+ const icon = getIndicatorIcon(container);
+ expect(icon).toHaveClass('astryx-multi-selector-indicator-icon');
+ expect(icon).toHaveClass('astryx-icon');
+ // Open/closed state is reflected so a theme can target each state alone.
+ expect(icon).toHaveAttribute('data-state', 'collapsed');
+ });
+
+ it('reflects the expanded state on the chevron when the popover is open', async () => {
+ const user = userEvent.setup();
+ const {container} = render(
+ <MultiSelector
+ label="Fruit"
+ options={ICON_OPTIONS}
+ value={[]}
+ onChange={() => {}}
+ />,
+ );
+ await user.click(screen.getByRole('combobox'));
+ await waitFor(() => {
+ expect(getIndicatorIcon(container)).toHaveAttribute(
+ 'data-state',
+ 'expanded',
+ );
+ });
+ });
+
+ it('renders the default icon (inherit color, sm size) byte-identically', () => {
+ // Pixel-identical default guard: the chevron glyph must carry the exact
+ // same StyleX color/size classes as a standalone inherit/sm icon. The added
+ // target class + data-state are purely additive — they change nothing until
+ // a theme targets them.
+ const {container} = render(
+ <MultiSelector
+ label="Fruit"
+ options={ICON_OPTIONS}
+ value={[]}
+ onChange={() => {}}
+ />,
+ );
+ const icon = getIndicatorIcon(container);
+
+ const {container: refContainer} = render(
+ <Icon icon="chevronDown" size="sm" color="inherit" />,
+ );
+ const refIcon = refContainer.querySelector('.astryx-icon') as HTMLElement;
+
+ // Exclude the additive theme-target classes (the stable target + its
+ // reflected state class) so only the StyleX color/size classes remain.
+ const themeTargetClasses = new Set([
+ 'astryx-multi-selector-indicator-icon',
+ 'collapsed',
+ 'expanded',
+ ]);
+ const styleClasses = (el: HTMLElement) =>
+ el.className
+ .split(' ')
+ .filter(c => !themeTargetClasses.has(c))
+ .sort();
+
+ expect(styleClasses(icon)).toEqual(styleClasses(refIcon));
+ });
+
+ it('exposes multi-selector-indicator-icon so a theme reaches the icon size and per-state color', () => {
+ // jsdom cannot resolve the @layer cascade, so the DOM-class assertions
+ // above (target lands on the icon element) plus this generation assertion
+ // (the theme emits same-element icon rules in @layer astryx-theme) together
+ // prove the seam: a same-element theme rule wins over the icon's own
+ // base-layer color/size.
+ const theme = defineTheme({
+ name: 'multi-selector-indicator-icon-test',
+ components: {
+ 'multi-selector-indicator-icon': {
+ base: {width: '14px', height: '14px', fontSize: '14px'},
+ 'state:expanded': {color: 'var(--color-icon-primary)'},
+ },
+ },
+ });
+ const css = generateThemeCSSFlat(theme);
+ expect(css).toContain('.astryx-multi-selector-indicator-icon {');
+ expect(css).toContain('width: 14px');
+ expect(css).toContain('height: 14px');
+ expect(css).toContain('.astryx-multi-selector-indicator-icon.expanded');
+ expect(css).toContain('color: var(--color-icon-primary)');
+ });
+});
diff --git a/packages/core/src/MultiSelector/MultiSelector.tsx b/packages/core/src/MultiSelector/MultiSelector.tsx
index 429269423b..26396725a6 100644
--- a/packages/core/src/MultiSelector/MultiSelector.tsx
+++ b/packages/core/src/MultiSelector/MultiSelector.tsx
@@ -1377,7 +1377,17 @@ export function MultiSelector<T extends MultiSelectorOptionType>({
onClick={handleClear}
aria-label={t('@astryx.multiSelector.clearAll', {label})}
{...stylex.props(styles.clearButton)}>
- <Icon icon="close" size="sm" color="secondary" />
+ <Icon
+ icon="close"
+ size="sm"
+ color="secondary"
+ // Stable theme target on the clear glyph itself, so a theme can
+ // restyle just this icon (color, size, hover) via `defineTheme`.
+ // Same-element rules in @layer astryx-theme win over the icon's
+ // own base color/size, which a button-level target could not
+ // reach.
+ {...themeProps('multi-selector-clear-icon')}
+ />
</button>
)}
<span
@@ -1393,7 +1403,19 @@ export function MultiSelector<T extends MultiSelectorOptionType>({
color={STATUS_ICON_COLOR_MAP[status.type]}
/>
) : (
- <Icon icon="chevronDown" size="sm" color="inherit" />
+ <Icon
+ icon="chevronDown"
+ size="sm"
+ color="inherit"
+ // Stable theme target on the chevron glyph itself, so a theme can
+ // restyle just this icon (color, size, hover) — and its
+ // open/closed state — via `defineTheme`. Same-element rules in
+ // @layer astryx-theme win over the icon's own base color/size,
+ // which a button-level target could not reach.
+ {...themeProps('multi-selector-indicator-icon', {
+ state: popover.isOpen ? 'expanded' : 'collapsed',
+ })}
+ />
)}
</span>
</div>
diff --git a/packages/core/src/Selector/Selector.doc.mjs b/packages/core/src/Selector/Selector.doc.mjs
index a19dbde75b..b1c37456f1 100644
--- a/packages/core/src/Selector/Selector.doc.mjs
+++ b/packages/core/src/Selector/Selector.doc.mjs
@@ -23,6 +23,8 @@ export const docs = {
targets: [
{className: 'astryx-selector', visualProps: ['size', 'status']},
{className: 'astryx-selector-option'},
+ {className: 'astryx-selector-clear-icon'},
+ {className: 'astryx-selector-indicator-icon', states: ['state']},
],
},
description: 'Dropdown selector for choosing from a list of options.',
diff --git a/packages/core/src/Selector/Selector.test.tsx b/packages/core/src/Selector/Selector.test.tsx
index 02cec29b55..710cf4cbbf 100644
--- a/packages/core/src/Selector/Selector.test.tsx
+++ b/packages/core/src/Selector/Selector.test.tsx
@@ -20,8 +20,11 @@ import {
import userEvent from '@testing-library/user-event';
import {Selector} from './Selector';
import {SelectorOption} from './SelectorOption';
+import {Icon} from '../Icon';
import {InputGroup, InputGroupText} from '../InputGroup';
import {__resetLiveRegionsForTest} from '../hooks/useAnnounce';
+import {defineTheme} from '../theme/defineTheme';
+import {generateThemeCSSFlat} from '../theme/generateThemeRules';
function politeRegion(): HTMLElement | null {
return document.querySelector('[data-astryx-live-region="polite"]');
@@ -832,15 +835,9 @@ describe('Selector', () => {
'Blueberry',
]);
await user.keyboard('{ArrowDown}');
- expect(search).toHaveAttribute(
- 'aria-activedescendant',
- options[0].id,
- );
+ expect(search).toHaveAttribute('aria-activedescendant', options[0].id);
await user.keyboard('{ArrowDown}');
- expect(search).toHaveAttribute(
- 'aria-activedescendant',
- options[1].id,
- );
+ expect(search).toHaveAttribute('aria-activedescendant', options[1].id);
});
it('shows the empty state when no group has a match', async () => {
@@ -1193,11 +1190,14 @@ describe('Selector', () => {
});
});
-
describe('Selector statusVariant forwarding', () => {
it('defaults to attached (status renders with data-variant="attached")', () => {
const {container} = render(
- <Selector label="Fruit" options={['Apple', 'Banana']} status={{type: 'error', message: 'Required'}} />,
+ <Selector
+ label="Fruit"
+ options={['Apple', 'Banana']}
+ status={{type: 'error', message: 'Required'}}
+ />,
);
expect(container.querySelector('.astryx-field-status')).toHaveAttribute(
'data-variant',
@@ -1207,7 +1207,12 @@ describe('Selector statusVariant forwarding', () => {
it('forwards statusVariant="detached" to the underlying Field status', () => {
const {container} = render(
- <Selector label="Fruit" options={['Apple', 'Banana']} status={{type: 'error', message: 'Required'}} statusVariant="detached" />,
+ <Selector
+ label="Fruit"
+ options={['Apple', 'Banana']}
+ status={{type: 'error', message: 'Required'}}
+ statusVariant="detached"
+ />,
);
expect(container.querySelector('.astryx-field-status')).toHaveAttribute(
'data-variant',
@@ -1215,3 +1220,204 @@ describe('Selector statusVariant forwarding', () => {
);
});
});
+
+describe('Selector clear icon theme target', () => {
+ // Resolve the clear glyph span (the astryx-icon element inside the clear
+ // button), independent of the theme target class.
+ const getClearIcon = (): HTMLElement => {
+ const button = screen.getByRole('button', {name: 'Clear Fruit'});
+ const icon = button.querySelector('.astryx-icon');
+ if (icon == null) {
+ throw new Error('clear icon not found');
+ }
+ return icon as HTMLElement;
+ };
+
+ it('renders the astryx-selector-clear-icon target on the clear glyph', () => {
+ render(
+ <Selector
+ label="Fruit"
+ options={OPTIONS}
+ value="Banana"
+ onChange={() => {}}
+ hasClear
+ />,
+ );
+ // The stable theme target lands on the icon element itself (not the
+ // button), so a theme can restyle just this glyph (color, size, hover)
+ // via `defineTheme` — a button-level target could not reach the icon's
+ // own color/size.
+ const icon = getClearIcon();
+ expect(icon).toHaveClass('astryx-selector-clear-icon');
+ expect(icon).toHaveClass('astryx-icon');
+ });
+
+ it('keeps the clear button functional alongside the target', () => {
+ const onChange = vi.fn();
+ render(
+ <Selector
+ label="Fruit"
+ options={OPTIONS}
+ value="Banana"
+ onChange={onChange}
+ hasClear
+ />,
+ );
+ const clear = screen.getByRole('button', {name: 'Clear Fruit'});
+ expect(clear.tagName).toBe('BUTTON');
+ fireEvent.click(clear);
+ expect(onChange).toHaveBeenCalledWith(null);
+ });
+
+ it('renders the default icon (secondary color, sm size) byte-identically', () => {
+ // Pixel-identical default guard: the clear glyph must carry the exact same
+ // StyleX color/size classes as a standalone secondary/sm icon. The added
+ // target class is purely additive — it changes nothing until a theme
+ // targets it.
+ render(
+ <Selector
+ label="Fruit"
+ options={OPTIONS}
+ value="Banana"
+ onChange={() => {}}
+ hasClear
+ />,
+ );
+ const icon = getClearIcon();
+
+ const {container: refContainer} = render(
+ <Icon icon="close" size="sm" color="secondary" />,
+ );
+ const refIcon = refContainer.querySelector('.astryx-icon') as HTMLElement;
+
+ const styleClasses = (el: HTMLElement) =>
+ el.className
+ .split(' ')
+ .filter(c => c !== 'astryx-selector-clear-icon')
+ .sort();
+
+ expect(styleClasses(icon)).toEqual(styleClasses(refIcon));
+ });
+
+ it('exposes selector-clear-icon so a theme reaches the icon color, size, and hover', () => {
+ // jsdom cannot resolve the @layer cascade, so the DOM-class assertion above
+ // (target lands on the icon element) plus this generation assertion (the
+ // theme emits same-element icon rules in @layer astryx-theme) together
+ // prove the seam: a same-element theme rule wins over the icon's own
+ // base-layer color/size.
+ const theme = defineTheme({
+ name: 'selector-clear-icon-test',
+ components: {
+ 'selector-clear-icon': {
+ base: {
+ width: '12px',
+ height: '12px',
+ fontSize: '12px',
+ color: 'var(--color-icon-secondary)',
+ ':hover': {color: 'var(--color-icon-primary)'},
+ },
+ },
+ },
+ });
+ const css = generateThemeCSSFlat(theme);
+ expect(css).toContain('.astryx-selector-clear-icon {');
+ expect(css).toContain('width: 12px');
+ expect(css).toContain('height: 12px');
+ expect(css).toContain('.astryx-selector-clear-icon:hover {');
+ expect(css).toContain('color: var(--color-icon-primary)');
+ });
+});
+
+describe('Selector indicator (chevron) icon theme target', () => {
+ const getIndicatorIcon = (container: HTMLElement): HTMLElement => {
+ // The chevron is the only glyph carrying the indicator target class.
+ const icon = container.querySelector('.astryx-selector-indicator-icon');
+ if (icon == null) {
+ throw new Error('indicator icon not found');
+ }
+ return icon as HTMLElement;
+ };
+
+ it('renders the astryx-selector-indicator-icon target on the chevron glyph', () => {
+ const {container} = render(
+ <Selector label="Fruit" options={OPTIONS} onChange={() => {}} />,
+ );
+ // The stable theme target lands on the icon element itself (not the trigger
+ // button), so a theme can restyle just this glyph (color, size, hover) —
+ // and each open/closed state — via `defineTheme`. A button-level target
+ // could not reach the icon's own color/size.
+ const icon = getIndicatorIcon(container);
+ expect(icon).toHaveClass('astryx-selector-indicator-icon');
+ expect(icon).toHaveClass('astryx-icon');
+ // Open/closed state is reflected so a theme can target each state alone.
+ expect(icon).toHaveAttribute('data-state', 'collapsed');
+ });
+
+ it('reflects the expanded state on the chevron when the popover is open', async () => {
+ const user = userEvent.setup();
+ const {container} = render(
+ <Selector label="Fruit" options={OPTIONS} onChange={() => {}} />,
+ );
+ await user.click(screen.getByRole('combobox'));
+ await waitFor(() => {
+ expect(getIndicatorIcon(container)).toHaveAttribute(
+ 'data-state',
+ 'expanded',
+ );
+ });
+ });
+
+ it('renders the default icon (inherit color, sm size) byte-identically', () => {
+ // Pixel-identical default guard: the chevron glyph must carry the exact
+ // same StyleX color/size classes as a standalone inherit/sm icon. The added
+ // target class + data-state are purely additive — they change nothing until
+ // a theme targets them.
+ const {container} = render(
+ <Selector label="Fruit" options={OPTIONS} onChange={() => {}} />,
+ );
+ const icon = getIndicatorIcon(container);
+
+ const {container: refContainer} = render(
+ <Icon icon="chevronDown" size="sm" color="inherit" />,
+ );
+ const refIcon = refContainer.querySelector('.astryx-icon') as HTMLElement;
+
+ // Exclude the additive theme-target classes (the stable target + its
+ // reflected state class) so only the StyleX color/size classes remain.
+ const themeTargetClasses = new Set([
+ 'astryx-selector-indicator-icon',
+ 'collapsed',
+ 'expanded',
+ ]);
+ const styleClasses = (el: HTMLElement) =>
+ el.className
+ .split(' ')
+ .filter(c => !themeTargetClasses.has(c))
+ .sort();
+
+ expect(styleClasses(icon)).toEqual(styleClasses(refIcon));
+ });
+
+ it('exposes selector-indicator-icon so a theme reaches the icon size and per-state color', () => {
+ // jsdom cannot resolve the @layer cascade, so the DOM-class assertions
+ // above (target lands on the icon element) plus this generation assertion
+ // (the theme emits same-element icon rules in @layer astryx-theme) together
+ // prove the seam: a same-element theme rule wins over the icon's own
+ // base-layer color/size.
+ const theme = defineTheme({
+ name: 'selector-indicator-icon-test',
+ components: {
+ 'selector-indicator-icon': {
+ base: {width: '14px', height: '14px', fontSize: '14px'},
+ 'state:expanded': {color: 'var(--color-icon-primary)'},
+ },
+ },
+ });
+ const css = generateThemeCSSFlat(theme);
+ expect(css).toContain('.astryx-selector-indicator-icon {');
+ expect(css).toContain('width: 14px');
+ expect(css).toContain('height: 14px');
+ expect(css).toContain('.astryx-selector-indicator-icon.expanded');
+ expect(css).toContain('color: var(--color-icon-primary)');
+ });
+});
diff --git a/packages/core/src/Selector/Selector.tsx b/packages/core/src/Selector/Selector.tsx
index fceb5e5883..f8ec4acc49 100644
--- a/packages/core/src/Selector/Selector.tsx
+++ b/packages/core/src/Selector/Selector.tsx
@@ -1109,7 +1109,17 @@ export function Selector<T extends SelectorOptionType>(
onClick={handleClear}
aria-label={t('@astryx.selector.clearLabel', {label})}
{...stylex.props(styles.clearButton)}>
- <Icon icon="close" size="sm" color="secondary" />
+ <Icon
+ icon="close"
+ size="sm"
+ color="secondary"
+ // Stable theme target on the clear glyph itself, so a theme can
+ // restyle just this icon (color, size, hover) via `defineTheme`.
+ // Same-element rules in @layer astryx-theme win over the icon's
+ // own base color/size, which a button-level target could not
+ // reach.
+ {...themeProps('selector-clear-icon')}
+ />
</button>
)}
<span
@@ -1125,7 +1135,19 @@ export function Selector<T extends SelectorOptionType>(
color={STATUS_ICON_COLOR_MAP[status.type]}
/>
) : (
- <Icon icon="chevronDown" size="sm" color="inherit" />
+ <Icon
+ icon="chevronDown"
+ size="sm"
+ color="inherit"
+ // Stable theme target on the chevron glyph itself, so a theme can
+ // restyle just this icon (color, size, hover) — and its
+ // open/closed state — via `defineTheme`. Same-element rules in
+ // @layer astryx-theme win over the icon's own base color/size,
+ // which a button-level target could not reach.
+ {...themeProps('selector-indicator-icon', {
+ state: popover.isOpen ? 'expanded' : 'collapsed',
+ })}
+ />
)}
</span>
</div>