Skip to content

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

TypeScript

feat(core): converge input clear buttons on a shared themeable primitive (#4876)

freddymeta5f71f07006b0
diff --git a/.changeset/input-clear-icon-theme-targets.md b/.changeset/input-clear-icon-theme-targets.md
new file mode 100644
index 0000000000..cad7c246d6
--- /dev/null
+++ b/.changeset/input-clear-icon-theme-targets.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[feat] Every clearable input now renders its clear (✕) affordance through the shared `InputClearButton`, so the glyph is themeable in one place via the `astryx-input-clear-icon` target instead of a per-component target or a fragile descendant selector. The component-specific `astryx-{date-input,date-range-input,selector,multi-selector}-clear-icon` targets still render for a deprecation window — migrate to `input-clear-icon`. The clear glyph is now a consistent secondary-color icon with a ghost-button hover affordance across the whole family.
+
+@freddymeta
diff --git a/packages/core/src/DateInput/DateInput.doc.mjs b/packages/core/src/DateInput/DateInput.doc.mjs
index 27f5baff52..19c31eb8de 100644
--- a/packages/core/src/DateInput/DateInput.doc.mjs
+++ b/packages/core/src/DateInput/DateInput.doc.mjs
@@ -173,7 +173,7 @@ export const docs = {
targets: [
{className: 'astryx-date-input', visualProps: ['size', 'status'], states: ['disabled']},
{className: 'astryx-date-input-toggle-icon', states: ['state']},
- {className: 'astryx-date-input-clear-icon'},
+ {className: 'astryx-date-input-clear-icon', deprecatedFor: 'input-clear-icon'},
],
},
usage: {
@@ -452,7 +452,7 @@ export const docsZh = {
states: ['disabled'],
},
{className: 'astryx-date-input-toggle-icon', states: ['state']},
- {className: 'astryx-date-input-clear-icon'},
+ {className: 'astryx-date-input-clear-icon', deprecatedFor: 'input-clear-icon'},
],
},
};
diff --git a/packages/core/src/DateInput/DateInput.test.tsx b/packages/core/src/DateInput/DateInput.test.tsx
index db7bde05a2..916bc55190 100644
--- a/packages/core/src/DateInput/DateInput.test.tsx
+++ b/packages/core/src/DateInput/DateInput.test.tsx
@@ -1049,7 +1049,7 @@ describe('DateInput clear icon theme target', () => {
return icon as HTMLElement;
};
- it('renders the astryx-date-input-clear-icon target on the clear glyph', () => {
+ it('renders the astryx-input-clear-icon target (plus the legacy alias) on the clear glyph', () => {
render(
<DateInput
label="Date"
@@ -1058,11 +1058,13 @@ describe('DateInput clear icon theme target', () => {
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.
+ // The canonical 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. The original per-component name rides along for a
+ // deprecation window.
const icon = getClearIcon();
+ expect(icon).toHaveClass('astryx-input-clear-icon');
expect(icon).toHaveClass('astryx-date-input-clear-icon');
expect(icon).toHaveClass('astryx-icon');
});
@@ -1083,11 +1085,13 @@ describe('DateInput clear icon theme target', () => {
expect(onChange).toHaveBeenCalledWith(undefined);
});
- 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.
+ it('routes the clear glyph through the shared clear button, keeping the legacy target', () => {
+ // The clear affordance now composes the shared InputClearButton (a ghost
+ // Button with a secondary/sm glyph), so the icon carries the canonical
+ // `astryx-input-clear-icon` target and — for a deprecation window — the
+ // original `astryx-date-input-clear-icon`. Aside from those target classes
+ // it matches the shared button's own `close`/`sm`/`secondary` glyph
+ // exactly, so the default look is defined in one place.
render(
<DateInput
label="Date"
@@ -1097,6 +1101,8 @@ describe('DateInput clear icon theme target', () => {
/>,
);
const icon = getClearIcon();
+ expect(icon).toHaveClass('astryx-input-clear-icon');
+ expect(icon).toHaveClass('astryx-date-input-clear-icon');
const {container: refContainer} = render(
<Icon icon="close" size="sm" color="secondary" />,
@@ -1106,7 +1112,11 @@ describe('DateInput clear icon theme target', () => {
const styleClasses = (el: HTMLElement) =>
el.className
.split(' ')
- .filter(c => c !== 'astryx-date-input-clear-icon')
+ .filter(
+ c =>
+ c !== 'astryx-input-clear-icon' &&
+ c !== 'astryx-date-input-clear-icon',
+ )
.sort();
expect(styleClasses(icon)).toEqual(styleClasses(refIcon));
diff --git a/packages/core/src/DateInput/DateInput.tsx b/packages/core/src/DateInput/DateInput.tsx
index e46618c2f5..2c68e197ce 100644
--- a/packages/core/src/DateInput/DateInput.tsx
+++ b/packages/core/src/DateInput/DateInput.tsx
@@ -35,6 +35,7 @@ import {
} from '../theme/tokens.stylex';
import {
Field,
+ InputClearButton,
type InputStatus,
inputWrapperStyles,
inputStatusBorderStyles,
@@ -162,6 +163,7 @@ import {mergeProps, mergeRefs, isFocusDetached} from '../utils';
import type {BaseProps} from '../BaseProps';
import type {SizeValue} from '../utils/types';
import {themeProps} from '../utils/themeProps';
+import {stableClassName} from '../naming';
import {useTranslator} from '../i18n';
export interface DateInputProps extends Omit<
@@ -755,22 +757,11 @@ export function DateInput({
{!isInputValid ? 'Invalid date' : ''}
</VisuallyHidden>
{hasClear && value !== undefined && !isEffectivelyDisabled && (
- <button
- type="button"
+ <InputClearButton
+ label={t('@astryx.dateInput.clear', {label})}
onClick={handleClear}
- aria-label={t('@astryx.dateInput.clear', {label})}
- {...stylex.props(styles.iconButton)}>
- <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('date-input-clear-icon')}
- />
- </button>
+ iconClassName={stableClassName('date-input-clear-icon')}
+ />
)}
{isBusy && <Spinner size="sm" />}
{statusIcon}
diff --git a/packages/core/src/DateRangeInput/DateRangeInput.doc.mjs b/packages/core/src/DateRangeInput/DateRangeInput.doc.mjs
index 45d0131cc5..2dc21fd8f6 100644
--- a/packages/core/src/DateRangeInput/DateRangeInput.doc.mjs
+++ b/packages/core/src/DateRangeInput/DateRangeInput.doc.mjs
@@ -168,7 +168,7 @@ export const docs = {
targets: [
{className: 'astryx-date-range-input', visualProps: ['size', 'status'], states: ['disabled']},
{className: 'astryx-date-range-input-toggle-icon', states: ['state']},
- {className: 'astryx-date-range-input-clear-icon'},
+ {className: 'astryx-date-range-input-clear-icon', deprecatedFor: 'input-clear-icon'},
],
},
usage: {
diff --git a/packages/core/src/DateRangeInput/DateRangeInput.test.tsx b/packages/core/src/DateRangeInput/DateRangeInput.test.tsx
index 71dc54f4d6..de4902e98f 100644
--- a/packages/core/src/DateRangeInput/DateRangeInput.test.tsx
+++ b/packages/core/src/DateRangeInput/DateRangeInput.test.tsx
@@ -592,7 +592,7 @@ describe('DateRangeInput icon theme targets', () => {
return icon as HTMLElement;
};
- it('renders astryx-date-range-input-clear-icon on the clear glyph', () => {
+ it('renders astryx-input-clear-icon (plus the legacy alias) on the clear glyph', () => {
render(
<DateRangeInput
label="Range"
@@ -601,10 +601,13 @@ describe('DateRangeInput icon theme targets', () => {
hasClear
/>,
);
- // The stable 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.
+ // The canonical 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. The original per-component name rides along for a
+ // deprecation window.
const icon = iconIn(getButton('Clear Range'));
+ expect(icon).toHaveClass('astryx-input-clear-icon');
expect(icon).toHaveClass('astryx-date-range-input-clear-icon');
expect(icon).toHaveClass('astryx-icon');
});
@@ -618,11 +621,12 @@ describe('DateRangeInput icon theme targets', () => {
expect(icon).toHaveAttribute('data-state', 'collapsed');
});
- it('renders the default icons (secondary color, sm size) byte-identically', () => {
- // Pixel-identical default guard: the glyphs 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.
+ it('routes the clear glyph through the shared clear button (default look unchanged)', () => {
+ // Default-look guard for the clear affordance. It now composes the shared
+ // InputClearButton (a ghost Button with a secondary/sm glyph), so aside
+ // from its target classes the glyph matches a standalone `secondary`/`sm`
+ // close icon — the default clear look is defined once, in InputClearButton.
+ // (The calendar-toggle glyph is covered separately.)
render(
<DateRangeInput
label="Range"
@@ -633,22 +637,24 @@ describe('DateRangeInput icon theme targets', () => {
);
const clearIcon = iconIn(getButton('Clear Range'));
- const {container: refContainer} = render(
+ const {container: clearRefContainer} = render(
<Icon icon="close" size="sm" color="secondary" />,
);
- const refIcon = refContainer.querySelector('.astryx-icon') as HTMLElement;
+ const clearRefIcon = clearRefContainer.querySelector(
+ '.astryx-icon',
+ ) as HTMLElement;
const styleClasses = (el: HTMLElement) =>
el.className
.split(' ')
.filter(
c =>
- c !== 'astryx-date-range-input-clear-icon' &&
- c !== 'astryx-date-range-input-toggle-icon',
+ c !== 'astryx-input-clear-icon' &&
+ c !== 'astryx-date-range-input-clear-icon',
)
.sort();
- expect(styleClasses(clearIcon)).toEqual(styleClasses(refIcon));
+ expect(styleClasses(clearIcon)).toEqual(styleClasses(clearRefIcon));
});
it('exposes the icon targets so a theme reaches icon color, size, and hover', () => {
diff --git a/packages/core/src/DateRangeInput/DateRangeInput.tsx b/packages/core/src/DateRangeInput/DateRangeInput.tsx
index 660163b35a..9195b36b85 100644
--- a/packages/core/src/DateRangeInput/DateRangeInput.tsx
+++ b/packages/core/src/DateRangeInput/DateRangeInput.tsx
@@ -36,6 +36,7 @@ import {
} from '../theme/tokens.stylex';
import {
Field,
+ InputClearButton,
type InputStatus,
inputWrapperStyles,
inputStatusBorderStyles,
@@ -60,6 +61,7 @@ import type {SizeValue} from '../utils/types';
import {useSize} from '../SizeContext/SizeContext';
import {useInputStatusIcon} from '../hooks/useInputStatusIcon';
import {themeProps} from '../utils/themeProps';
+import {stableClassName} from '../naming';
import {useTranslator} from '../i18n';
export type {DateRange} from '../Calendar';
@@ -628,18 +630,11 @@ export function DateRangeInput({
{displayValue || placeholder}
</button>
{hasClear && value !== null && !isEffectivelyDisabled && (
- <button
- type="button"
+ <InputClearButton
+ label={t('@astryx.dateInput.clear', {label})}
onClick={handleClear}
- aria-label={t('@astryx.dateInput.clear', {label})}
- {...stylex.props(styles.iconButton)}>
- <Icon
- icon="close"
- size="sm"
- color="secondary"
- {...themeProps('date-range-input-clear-icon')}
- />
- </button>
+ iconClassName={stableClassName('date-range-input-clear-icon')}
+ />
)}
{isBusy && <Spinner size="sm" />}
{statusIcon}
diff --git a/packages/core/src/DateTimeInput/DateTimeInput.tsx b/packages/core/src/DateTimeInput/DateTimeInput.tsx
index 280b76561b..20dd2437f9 100644
--- a/packages/core/src/DateTimeInput/DateTimeInput.tsx
+++ b/packages/core/src/DateTimeInput/DateTimeInput.tsx
@@ -38,6 +38,7 @@ import {
} from '../theme/tokens.stylex';
import {
Field,
+ InputClearButton,
type InputStatus,
inputWrapperStyles,
inputStatusBorderStyles,
@@ -990,13 +991,10 @@ export function DateTimeInput({
{!isDateInputValid ? 'Invalid date' : ''}
</VisuallyHidden>
{hasClear && value !== undefined && !isEffectivelyDisabled && (
- <button
- type="button"
+ <InputClearButton
+ label={t('@astryx.dateInput.clear', {label})}
onClick={handleClear}
- aria-label={t('@astryx.dateInput.clear', {label})}
- {...stylex.props(styles.iconButton)}>
- <Icon icon="close" size="sm" color="secondary" />
- </button>
+ />
)}
{isBusy && <Spinner size="sm" />}
{statusIcon}
diff --git a/packages/core/src/Field/Field.doc.mjs b/packages/core/src/Field/Field.doc.mjs
index cffd91d05d..3350be5232 100644
--- a/packages/core/src/Field/Field.doc.mjs
+++ b/packages/core/src/Field/Field.doc.mjs
@@ -34,6 +34,7 @@ export const docs = {
className: 'astryx-input-status-icon',
visualProps: ['size', 'status'],
},
+ {className: 'astryx-input-clear-icon'},
],
vars: [
{name: '--_field-radius', description: 'Border radius of input fields', default: 'var(--radius-element)', private: true},
diff --git a/packages/core/src/Field/InputClearButton.test.tsx b/packages/core/src/Field/InputClearButton.test.tsx
new file mode 100644
index 0000000000..55cc61761b
--- /dev/null
+++ b/packages/core/src/Field/InputClearButton.test.tsx
@@ -0,0 +1,117 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+/**
+ * @file InputClearButton.test.tsx
+ * @input Uses vitest, @testing-library/react, InputClearButton, Icon, theme
+ * @output Unit tests for the shared clear-button primitive
+ * @position Testing; validates InputClearButton.tsx — the single home for the
+ * clearable input family's clear (✕) affordance and its theme target.
+ *
+ * SYNC: When InputClearButton.tsx changes, update tests to match new behavior.
+ */
+
+import {describe, it, expect, vi} from 'vitest';
+import {render, screen, fireEvent} from '@testing-library/react';
+import {InputClearButton} from './InputClearButton';
+import {Icon} from '../Icon';
+import {defineTheme} from '../theme/defineTheme';
+import {generateThemeCSS} from '../theme/generateThemeRules';
+
+function generateThemeTestCSS(theme: Parameters<typeof generateThemeCSS>[0]) {
+ const {prose, component} = generateThemeCSS(theme);
+ return [prose, component].filter(Boolean).join('\n\n');
+}
+
+const getGlyph = (): HTMLElement => {
+ const button = screen.getByRole('button', {name: 'Clear'});
+ const icon = button.querySelector('.astryx-icon');
+ if (icon == null) {
+ throw new Error('clear glyph not found');
+ }
+ return icon as HTMLElement;
+};
+
+describe('InputClearButton', () => {
+ it('renders a real button with the given accessible label', () => {
+ render(<InputClearButton label="Clear" onClick={() => {}} />);
+ const button = screen.getByRole('button', {name: 'Clear'});
+ expect(button.tagName).toBe('BUTTON');
+ });
+
+ it('fires onClick with the native event when pressed', () => {
+ const onClick = vi.fn();
+ render(<InputClearButton label="Clear" onClick={onClick} />);
+ fireEvent.click(screen.getByRole('button', {name: 'Clear'}));
+ expect(onClick).toHaveBeenCalledTimes(1);
+ expect(onClick.mock.calls[0][0]).toBeInstanceOf(Object);
+ });
+
+ it('renders the astryx-input-clear-icon target on the glyph', () => {
+ // One canonical target on the icon element itself — so a theme restyles
+ // the clear glyph across the whole input family from a single place.
+ render(<InputClearButton label="Clear" onClick={() => {}} />);
+ const glyph = getGlyph();
+ expect(glyph).toHaveClass('astryx-input-clear-icon');
+ expect(glyph).toHaveClass('astryx-icon');
+ });
+
+ it('matches a standalone inherit/sm close icon aside from the target class', () => {
+ // The glyph is a secondary/sm close icon (matching the other field
+ // affordances — chevrons, calendar toggles, status icons); aside from the
+ // target class it is exactly that standalone Icon, so the default look is
+ // defined once here rather than per input.
+ render(<InputClearButton label="Clear" onClick={() => {}} />);
+ const glyph = getGlyph();
+
+ const {container} = render(
+ <Icon icon="close" size="sm" color="secondary" />,
+ );
+ const refIcon = container.querySelector('.astryx-icon') as HTMLElement;
+
+ const styleClasses = (el: HTMLElement) =>
+ el.className
+ .split(' ')
+ .filter(c => c !== 'astryx-input-clear-icon')
+ .sort();
+
+ expect(styleClasses(glyph)).toEqual(styleClasses(refIcon));
+ });
+
+ it('merges an extra iconClassName beside the canonical target', () => {
+ // Consumers that shipped a component-specific target before the family
+ // converged pass it through here to keep emitting it for a deprecation
+ // window.
+ render(
+ <InputClearButton
+ label="Clear"
+ onClick={() => {}}
+ iconClassName="astryx-date-input-clear-icon"
+ />,
+ );
+ const glyph = getGlyph();
+ expect(glyph).toHaveClass('astryx-input-clear-icon');
+ expect(glyph).toHaveClass('astryx-date-input-clear-icon');
+ });
+
+ it('exposes input-clear-icon so a theme reaches the glyph color, size, and hover', () => {
+ const theme = defineTheme({
+ name: 'input-clear-icon-test',
+ components: {
+ 'input-clear-icon': {
+ base: {
+ width: '12px',
+ height: '12px',
+ fontSize: '12px',
+ color: 'var(--color-icon-secondary)',
+ ':hover': {color: 'var(--color-icon-primary)'},
+ },
+ },
+ },
+ });
+ const css = generateThemeTestCSS(theme);
+ expect(css).toContain('.astryx-input-clear-icon {');
+ expect(css).toContain('width: 12px');
+ expect(css).toContain('.astryx-input-clear-icon:hover {');
+ expect(css).toContain('color: var(--color-icon-primary)');
+ });
+});
diff --git a/packages/core/src/Field/InputClearButton.tsx b/packages/core/src/Field/InputClearButton.tsx
index 1991f176b8..f0ad17fddb 100644
--- a/packages/core/src/Field/InputClearButton.tsx
+++ b/packages/core/src/Field/InputClearButton.tsx
@@ -5,14 +5,20 @@
/**
* @file InputClearButton.tsx
* @input Uses React, Button, Icon
- * @output Exports InputClearButton shared clear button for input components
- * @position Shared primitive; used by Typeahead, Tokenizer, TextInput
+ * @output Exports InputClearButton, the shared clear (✕) button rendered by
+ * every clearable input in the family.
+ * @position Shared primitive. Every input that renders a clear affordance —
+ * TextInput, NumberInput, TimeInput, DateInput, DateTimeInput,
+ * DateRangeInput, Selector, MultiSelector, Typeahead, Tokenizer, FileInput —
+ * routes it through here, so the glyph is themed in one place via the
+ * `astryx-input-clear-icon` target.
*/
import type {ReactNode} from 'react';
import * as stylex from '@stylexjs/stylex';
import {Button} from '../Button';
import {Icon} from '../Icon';
+import {themeProps} from '../utils/themeProps';
const styles = stylex.create({
button: {
@@ -25,19 +31,40 @@ export interface InputClearButtonProps {
label: string;
onClick: (e: React.MouseEvent<HTMLButtonElement>) => void;
xstyle?: stylex.StyleXStyles;
+ /**
+ * Extra class(es) for the clear glyph itself, merged onto the shared
+ * `astryx-input-clear-icon` target. Used by inputs that shipped a
+ * component-specific clear-icon target before the family converged here
+ * (e.g. `astryx-date-input-clear-icon`) to keep emitting it for a
+ * deprecation window; new callers don't need it.
+ */
+ iconClassName?: string;
}
export function InputClearButton({
label,
onClick,
xstyle,
+ iconClassName,
}: InputClearButtonProps): ReactNode {
+ const {className: iconTargetClassName} = themeProps('input-clear-icon');
return (
<Button
variant="ghost"
size="sm"
label={label}
- icon={<Icon icon="close" size="sm" color="inherit" />}
+ icon={
+ <Icon
+ icon="close"
+ size="sm"
+ color="secondary"
+ className={
+ iconClassName != null
+ ? `${iconTargetClassName} ${iconClassName}`
+ : iconTargetClassName
+ }
+ />
+ }
onClick={onClick}
isIconOnly
xstyle={[styles.button, xstyle]}
diff --git a/packages/core/src/MultiSelector/MultiSelector.doc.mjs b/packages/core/src/MultiSelector/MultiSelector.doc.mjs
index bfb111b651..16e856eb4f 100644
--- a/packages/core/src/MultiSelector/MultiSelector.doc.mjs
+++ b/packages/core/src/MultiSelector/MultiSelector.doc.mjs
@@ -25,7 +25,7 @@ export const docs = {
visualProps: ['variant', 'size', 'status'],
states: ['disabled'],
},
- {className: 'astryx-multi-selector-clear-icon'},
+ {className: 'astryx-multi-selector-clear-icon', deprecatedFor: 'input-clear-icon'},
{className: 'astryx-multi-selector-empty-state'},
{
className: 'astryx-multi-selector-indicator-icon',
diff --git a/packages/core/src/MultiSelector/MultiSelector.test.tsx b/packages/core/src/MultiSelector/MultiSelector.test.tsx
index 5fa61627a7..2b345d49d9 100644
--- a/packages/core/src/MultiSelector/MultiSelector.test.tsx
+++ b/packages/core/src/MultiSelector/MultiSelector.test.tsx
@@ -1546,7 +1546,7 @@ describe('MultiSelector clear icon theme target', () => {
return icon as HTMLElement;
};
- it('renders the astryx-multi-selector-clear-icon target on the clear glyph', () => {
+ it('renders the astryx-input-clear-icon target (plus the legacy alias) on the clear glyph', () => {
render(
<MultiSelector
label="Fruit"
@@ -1556,11 +1556,13 @@ describe('MultiSelector clear icon theme target', () => {
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.
+ // The canonical 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. The original per-component name rides along for a
+ // deprecation window.
const icon = getClearIcon();
+ expect(icon).toHaveClass('astryx-input-clear-icon');
expect(icon).toHaveClass('astryx-multi-selector-clear-icon');
expect(icon).toHaveClass('astryx-icon');
});
@@ -1582,11 +1584,13 @@ describe('MultiSelector clear icon theme target', () => {
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.
+ it('routes the clear glyph through the shared clear button, keeping the legacy target', () => {
+ // The clear affordance now composes the shared InputClearButton (a ghost
+ // Button with a secondary/sm glyph), so the icon carries the canonical
+ // `astryx-input-clear-icon` target and — for a deprecation window — the
+ // original `astryx-multi-selector-clear-icon`. Aside from those target
+ // classes it matches the shared button's own `close`/`sm`/`secondary`
+ // glyph exactly, so the default look is defined in one place.
render(
<MultiSelector
label="Fruit"
@@ -1597,6 +1601,8 @@ describe('MultiSelector clear icon theme target', () => {
/>,
);
const icon = getClearIcon();
+ expect(icon).toHaveClass('astryx-input-clear-icon');
+ expect(icon).toHaveClass('astryx-multi-selector-clear-icon');
const {container: refContainer} = render(
<Icon icon="close" size="sm" color="secondary" />,
@@ -1606,7 +1612,11 @@ describe('MultiSelector clear icon theme target', () => {
const styleClasses = (el: HTMLElement) =>
el.className
.split(' ')
- .filter(c => c !== 'astryx-multi-selector-clear-icon')
+ .filter(
+ c =>
+ c !== 'astryx-input-clear-icon' &&
+ c !== 'astryx-multi-selector-clear-icon',
+ )
.sort();
expect(styleClasses(icon)).toEqual(styleClasses(refIcon));
diff --git a/packages/core/src/MultiSelector/MultiSelector.tsx b/packages/core/src/MultiSelector/MultiSelector.tsx
index 0e4e7c1897..377cff6f61 100644
--- a/packages/core/src/MultiSelector/MultiSelector.tsx
+++ b/packages/core/src/MultiSelector/MultiSelector.tsx
@@ -34,6 +34,7 @@ import {Icon, renderIconSlot, type IconType} from '../Icon';
import type {IconName} from '../Icon';
import {
Field,
+ InputClearButton,
inputStatusBorderStyles,
inputStatusHoverShadowStyles,
inputWrapperStyles,
@@ -75,6 +76,7 @@ import type {BaseProps} from '../BaseProps';
import type {SizeValue} from '../utils/types';
import {useSize} from '../SizeContext/SizeContext';
import {themeProps} from '../utils/themeProps';
+import {stableClassName} from '../naming';
import {groupStyles} from '../InputGroup/groupStyles';
import {useInputGroup} from '../InputGroup/InputGroupContext';
import {VisuallyHidden} from '../VisuallyHidden';
@@ -222,23 +224,6 @@ const styles = stylex.create({
},
// Clear button
- clearButton: {
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- padding: 0,
- margin: 0,
- borderWidth: 0,
- borderStyle: 'none',
- backgroundColor: 'transparent',
- cursor: 'pointer',
- borderRadius: radiusVars['--radius-element'],
- outline: {
- default: 'none',
- ':focus-visible': `${borderVars['--border-width']} solid ${colorVars['--color-accent']}`,
- },
- outlineOffset: 1,
- },
statusButton: {
display: 'flex',
alignItems: 'center',
@@ -1536,23 +1521,11 @@ export function MultiSelector<T extends MultiSelectorOptionType>({
))}
{isBusy && <Spinner size="sm" />}
{hasClear && value.length > 0 && !isDisabled && (
- <button
- type="button"
+ <InputClearButton
+ label={t('@astryx.multiSelector.clearAll', {label})}
onClick={handleClear}
- aria-label={t('@astryx.multiSelector.clearAll', {label})}
- {...stylex.props(styles.clearButton)}>
- <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>
+ iconClassName={stableClassName('multi-selector-clear-icon')}
+ />
)}
{/*
No wrapper span: Icon's own span already provides the 16px box (`sm`)
diff --git a/packages/core/src/NumberInput/NumberInput.tsx b/packages/core/src/NumberInput/NumberInput.tsx
index b0152f63f6..bcc9a6519a 100644
--- a/packages/core/src/NumberInput/NumberInput.tsx
+++ b/packages/core/src/NumberInput/NumberInput.tsx
@@ -30,13 +30,12 @@ import * as stylex from '@stylexjs/stylex';
import {
colorVars,
sizeVars,
- radiusVars,
typographyVars,
typeScaleVars,
- borderVars,
} from '../theme/tokens.stylex';
import {
Field,
+ InputClearButton,
type InputStatus,
inputWrapperStyles,
inputStatusBorderStyles,
@@ -44,7 +43,7 @@ import {
inputStatusFocusWithinStyles,
type FieldStatusVariant,
} from '../Field';
-import {Icon, renderIconSlot, type IconType} from '../Icon';
+import {renderIconSlot, type IconType} from '../Icon';
import {VisuallyHidden} from '../VisuallyHidden';
import {useTooltip} from '../Tooltip';
import {getInputARIA} from '../utils';
@@ -57,23 +56,6 @@ const styles = stylex.create({
wrapper: {
zIndex: 1,
},
- clearButton: {
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- padding: 0,
- margin: 0,
- borderWidth: 0,
- borderStyle: 'none',
- backgroundColor: 'transparent',
- cursor: 'pointer',
- borderRadius: radiusVars['--radius-element'],
- outline: {
- default: 'none',
- ':focus-visible': `${borderVars['--border-width']} solid ${colorVars['--color-accent']}`,
- },
- outlineOffset: 1,
- },
input: {
display: 'block',
flex: 1,
@@ -713,13 +695,10 @@ export function NumberInput({
{!isInputValid ? 'Invalid number' : ''}
</VisuallyHidden>
{hasClear && value != null && !isDisabled && !isReadOnly && (
- <button
- type="button"
+ <InputClearButton
+ label={t('@astryx.numberInput.clearLabel', {label})}
onClick={handleClear}
- aria-label={t('@astryx.numberInput.clearLabel', {label})}
- {...stylex.props(styles.clearButton)}>
- <Icon icon="close" size="sm" color="secondary" />
- </button>
+ />
)}
{statusIcon}
</div>
diff --git a/packages/core/src/Selector/Selector.doc.mjs b/packages/core/src/Selector/Selector.doc.mjs
index 6183503bab..ebdeccbae3 100644
--- a/packages/core/src/Selector/Selector.doc.mjs
+++ b/packages/core/src/Selector/Selector.doc.mjs
@@ -28,7 +28,7 @@ export const docs = {
},
{className: 'astryx-selector-option'},
{className: 'astryx-selector-empty-state'},
- {className: 'astryx-selector-clear-icon'},
+ {className: 'astryx-selector-clear-icon', deprecatedFor: 'input-clear-icon'},
{className: 'astryx-selector-indicator-icon', states: ['state']},
{className: 'astryx-selector-check'},
],
diff --git a/packages/core/src/Selector/Selector.test.tsx b/packages/core/src/Selector/Selector.test.tsx
index ab6162dbea..dab7ca95ea 100644
--- a/packages/core/src/Selector/Selector.test.tsx
+++ b/packages/core/src/Selector/Selector.test.tsx
@@ -2093,7 +2093,7 @@ describe('Selector clear icon theme target', () => {
return icon as HTMLElement;
};
- it('renders the astryx-selector-clear-icon target on the clear glyph', () => {
+ it('renders the astryx-input-clear-icon target (plus the legacy alias) on the clear glyph', () => {
render(
<Selector
label="Fruit"
@@ -2103,11 +2103,13 @@ describe('Selector clear icon theme target', () => {
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.
+ // The canonical 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. The original per-component name rides along for a
+ // deprecation window.
const icon = getClearIcon();
+ expect(icon).toHaveClass('astryx-input-clear-icon');
expect(icon).toHaveClass('astryx-selector-clear-icon');
expect(icon).toHaveClass('astryx-icon');
});
@@ -2129,11 +2131,13 @@ describe('Selector clear icon theme target', () => {
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.
+ it('routes the clear glyph through the shared clear button, keeping the legacy target', () => {
+ // The clear affordance now composes the shared InputClearButton (a ghost
+ // Button with a secondary/sm glyph), so the icon carries the canonical
+ // `astryx-input-clear-icon` target and — for a deprecation window — the
+ // original `astryx-selector-clear-icon`. Aside from those target classes
+ // it matches the shared button's own `close`/`sm`/`secondary` glyph
+ // exactly, so the default look is defined in one place.
render(
<Selector
label="Fruit"
@@ -2144,6 +2148,8 @@ describe('Selector clear icon theme target', () => {
/>,
);
const icon = getClearIcon();
+ expect(icon).toHaveClass('astryx-input-clear-icon');
+ expect(icon).toHaveClass('astryx-selector-clear-icon');
const {container: refContainer} = render(
<Icon icon="close" size="sm" color="secondary" />,
@@ -2153,7 +2159,11 @@ describe('Selector clear icon theme target', () => {
const styleClasses = (el: HTMLElement) =>
el.className
.split(' ')
- .filter(c => c !== 'astryx-selector-clear-icon')
+ .filter(
+ c =>
+ c !== 'astryx-input-clear-icon' &&
+ c !== 'astryx-selector-clear-icon',
+ )
.sort();
expect(styleClasses(icon)).toEqual(styleClasses(refIcon));
@@ -2504,7 +2514,12 @@ describe('Selector disabled state theme target', () => {
it('reflects data-disabled="disabled" on the root when disabled', () => {
const {container} = render(
- <Selector label="Fruit" options={OPTIONS} onChange={() => {}} isDisabled />,
+ <Selector
+ label="Fruit"
+ options={OPTIONS}
+ onChange={() => {}}
+ isDisabled
+ />,
);
expect(getSelectorRoot(container)).toHaveAttribute(
'data-disabled',
@@ -2535,5 +2550,3 @@ describe('Selector disabled state theme target', () => {
expect(css).toContain('opacity: 0.4');
});
});
-
-
diff --git a/packages/core/src/Selector/Selector.tsx b/packages/core/src/Selector/Selector.tsx
index dbf74b0d4e..2353436eef 100644
--- a/packages/core/src/Selector/Selector.tsx
+++ b/packages/core/src/Selector/Selector.tsx
@@ -36,6 +36,7 @@ import {useIndicator} from '../Indicator';
import type {IconName} from '../Icon';
import {
Field,
+ InputClearButton,
inputStatusBorderStyles,
inputStatusHoverShadowStyles,
inputWrapperStyles,
@@ -75,6 +76,7 @@ import {useSize} from '../SizeContext/SizeContext';
import type {BaseProps} from '../BaseProps';
import type {SizeValue} from '../utils/types';
import {themeProps} from '../utils/themeProps';
+import {stableClassName} from '../naming';
import {groupStyles} from '../InputGroup/groupStyles';
import {useInputGroup} from '../InputGroup/InputGroupContext';
import {VisuallyHidden} from '../VisuallyHidden';
@@ -201,23 +203,6 @@ const styles = stylex.create({
},
// Clear button
- clearButton: {
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- padding: 0,
- margin: 0,
- borderWidth: 0,
- borderStyle: 'none',
- backgroundColor: 'transparent',
- cursor: 'pointer',
- borderRadius: radiusVars['--radius-element'],
- outline: {
- default: 'none',
- ':focus-visible': `${borderVars['--border-width']} solid ${colorVars['--color-accent']}`,
- },
- outlineOffset: 1,
- },
statusButton: {
display: 'flex',
alignItems: 'center',
@@ -1333,23 +1318,11 @@ export function Selector<T extends SelectorOptionType>(
)}
{isBusy && <Spinner size="sm" />}
{hasClear && value != null && !isDisabled && (
- <button
- type="button"
+ <InputClearButton
+ label={t('@astryx.selector.clearLabel', {label})}
onClick={handleClear}
- aria-label={t('@astryx.selector.clearLabel', {label})}
- {...stylex.props(styles.clearButton)}>
- <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>
+ iconClassName={stableClassName('selector-clear-icon')}
+ />
)}
{/*
No wrapper span: Icon's own span already provides the 16px box (`sm`)
diff --git a/packages/core/src/TextInput/TextInput.tsx b/packages/core/src/TextInput/TextInput.tsx
index 36f3329786..414e450781 100644
--- a/packages/core/src/TextInput/TextInput.tsx
+++ b/packages/core/src/TextInput/TextInput.tsx
@@ -30,13 +30,12 @@ import * as stylex from '@stylexjs/stylex';
import {
colorVars,
sizeVars,
- radiusVars,
typographyVars,
typeScaleVars,
- borderVars,
} from '../theme/tokens.stylex';
import {
Field,
+ InputClearButton,
type InputStatus,
inputWrapperStyles,
inputStatusBorderStyles,
@@ -44,30 +43,13 @@ import {
inputStatusFocusWithinStyles,
type FieldStatusVariant,
} from '../Field';
-import {Icon, renderIconSlot, type IconType} from '../Icon';
+import {renderIconSlot, type IconType} from '../Icon';
import {Spinner} from '../Spinner';
import {useTooltip} from '../Tooltip';
import {VisuallyHidden} from '../VisuallyHidden';
import {getInputARIA} from '../utils';
const styles = stylex.create({
- clearButton: {
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- padding: 0,
- margin: 0,
- borderWidth: 0,
- borderStyle: 'none',
- backgroundColor: 'transparent',
- cursor: 'pointer',
- borderRadius: radiusVars['--radius-element'],
- outline: {
- default: 'none',
- ':focus-visible': `${borderVars['--border-width']} solid ${colorVars['--color-accent']}`,
- },
- outlineOffset: 1,
- },
input: {
display: 'block',
flex: 1,
@@ -470,13 +452,10 @@ export function TextInput({
{...stylex.props(styles.input, isDisabled && styles.inputDisabled)}
/>
{hasClear && value !== '' && !isDisabled && !isReadOnly && (
- <button
- type="button"
+ <InputClearButton
+ label={t('@astryx.textInput.clearLabel', {label})}
onClick={handleClear}
- aria-label={t('@astryx.textInput.clearLabel', {label})}
- {...stylex.props(styles.clearButton)}>
- <Icon icon="close" size="sm" color="secondary" />
- </button>
+ />
)}
{isBusy && <Spinner size="sm" />}
{statusIcon}
diff --git a/packages/core/src/TimeInput/TimeInput.tsx b/packages/core/src/TimeInput/TimeInput.tsx
index 88edc40dd4..9890705213 100644
--- a/packages/core/src/TimeInput/TimeInput.tsx
+++ b/packages/core/src/TimeInput/TimeInput.tsx
@@ -32,13 +32,12 @@ import * as stylex from '@stylexjs/stylex';
import {
colorVars,
sizeVars,
- radiusVars,
typographyVars,
typeScaleVars,
- borderVars,
} from '../theme/tokens.stylex';
import {
Field,
+ InputClearButton,
type InputStatus,
inputWrapperStyles,
inputStatusBorderStyles,
@@ -106,23 +105,6 @@ const styles = stylex.create({
inputInvalid: {
color: colorVars['--color-text-secondary'],
},
- clearButton: {
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- padding: 0,
- margin: 0,
- borderWidth: 0,
- borderStyle: 'none',
- backgroundColor: 'transparent',
- cursor: 'pointer',
- borderRadius: radiusVars['--radius-element'],
- outline: {
- default: 'none',
- ':focus-visible': `${borderVars['--border-width']} solid ${colorVars['--color-accent']}`,
- },
- outlineOffset: 1,
- },
});
const sizeStyles = stylex.create({
@@ -681,13 +663,10 @@ export function TimeInput({
</VisuallyHidden>
{isBusy && <Spinner size="sm" />}
{hasClear && value && !isDisabled && (
- <button
- type="button"
+ <InputClearButton
+ label={t('@astryx.timeInput.clearLabel', {label})}
onClick={handleClear}
- aria-label={t('@astryx.timeInput.clearLabel', {label})}
- {...stylex.props(styles.clearButton)}>
- <Icon icon="close" size="sm" color="secondary" />
- </button>
+ />
)}
{statusIcon}
</div>