Skip to content

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

TypeScript

feat(field-status): add theme targets for the status icon (on-field + detached) (#4539)

freddymeta0f56f8214dbc
diff --git a/.changeset/input-status-icon-theme-target.md b/.changeset/input-status-icon-theme-target.md
new file mode 100644
index 0000000000..e9a9d69ad9
--- /dev/null
+++ b/.changeset/input-status-icon-theme-target.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[feat] Field/FieldStatus: add `astryx-input-status-icon` and `astryx-field-status-icon` theme targets on the field status glyph, so consumers can recolor, resize, and restyle it — per status — via `defineTheme` instead of a fragile descendant selector or raw CSS. `astryx-input-status-icon` sits on the on-field icon shared by all bordered inputs across the `attached` and `tooltip` status variants and reflects `data-size`/`data-status`; `astryx-field-status-icon` sits on the detached message box's leading icon and reflects `data-type`. Purely additive — default rendering is unchanged.
+
+@freddymeta
diff --git a/packages/core/src/Field/Field.doc.mjs b/packages/core/src/Field/Field.doc.mjs
index 064fa52f59..c91d71b5e8 100644
--- a/packages/core/src/Field/Field.doc.mjs
+++ b/packages/core/src/Field/Field.doc.mjs
@@ -30,6 +30,10 @@ export const docs = {
{className: 'astryx-field', visualProps: ['layout']},
{className: 'astryx-field-label'},
{className: 'astryx-field-status', visualProps: ['type', 'variant']},
+ {
+ className: 'astryx-input-status-icon',
+ visualProps: ['size', 'status'],
+ },
],
vars: [
{name: '--_field-radius', description: 'Border radius of input fields', default: 'var(--radius-element)', private: true},
diff --git a/packages/core/src/FieldStatus/FieldStatus.doc.mjs b/packages/core/src/FieldStatus/FieldStatus.doc.mjs
index 744788eb0a..c61342940e 100644
--- a/packages/core/src/FieldStatus/FieldStatus.doc.mjs
+++ b/packages/core/src/FieldStatus/FieldStatus.doc.mjs
@@ -12,6 +12,7 @@ export const docs = {
theming: {
targets: [
{className: 'astryx-field-status', visualProps: ['type', 'variant']},
+ {className: 'astryx-field-status-icon', visualProps: ['type']},
],
},
props: [
diff --git a/packages/core/src/FieldStatus/FieldStatus.test.tsx b/packages/core/src/FieldStatus/FieldStatus.test.tsx
index 113f11c073..2d53b101f3 100644
--- a/packages/core/src/FieldStatus/FieldStatus.test.tsx
+++ b/packages/core/src/FieldStatus/FieldStatus.test.tsx
@@ -372,6 +372,67 @@ describe('FieldStatus', () => {
});
});
+ describe('field-status-icon theme target', () => {
+ // The stable theme target lands on the detached message box's leading glyph
+ // itself, so a theme can restyle (e.g. resize) just this icon via
+ // `defineTheme`. It reflects the status type as a data attribute so themes
+ // can target per status, mirroring the parent astryx-field-status.
+ const getStatusIcon = (root: HTMLElement): HTMLElement => {
+ const icon = root.querySelector('.astryx-field-status-icon');
+ if (icon == null) {
+ throw new Error('status icon not found');
+ }
+ return icon as HTMLElement;
+ };
+
+ it('renders the target on the detached leading icon', () => {
+ render(
+ <FieldStatus
+ type="error"
+ message="msg"
+ variant="detached"
+ data-testid="fs"
+ />,
+ );
+ const icon = getStatusIcon(screen.getByTestId('fs'));
+ expect(icon).toHaveClass('astryx-field-status-icon');
+ expect(icon).toHaveClass('astryx-icon');
+ expect(icon).toHaveAttribute('data-type', 'error');
+ });
+
+ it('reflects the status type per status', () => {
+ for (const type of ['error', 'warning', 'success'] as const) {
+ const {unmount} = render(
+ <FieldStatus
+ type={type}
+ message="msg"
+ variant="detached"
+ data-testid="fs"
+ />,
+ );
+ expect(getStatusIcon(screen.getByTestId('fs'))).toHaveAttribute(
+ 'data-type',
+ type,
+ );
+ unmount();
+ }
+ });
+
+ it('does not render the target for the attached variant', () => {
+ render(
+ <FieldStatus
+ type="error"
+ message="msg"
+ variant="attached"
+ data-testid="fs"
+ />,
+ );
+ expect(
+ screen.getByTestId('fs').querySelector('.astryx-field-status-icon'),
+ ).toBeNull();
+ });
+ });
+
describe('edge cases', () => {
it('renders an empty message without crashing', () => {
render(<FieldStatus type="error" message="" data-testid="fs" />);
diff --git a/packages/core/src/FieldStatus/FieldStatus.tsx b/packages/core/src/FieldStatus/FieldStatus.tsx
index 5e0a76c92e..07fec97bb5 100644
--- a/packages/core/src/FieldStatus/FieldStatus.tsx
+++ b/packages/core/src/FieldStatus/FieldStatus.tsx
@@ -56,8 +56,8 @@ const styles = stylex.create({
paddingBlockStart: `calc(${spacingVars['--spacing-1-5']} + ${spacingVars['--spacing-2']})`,
paddingBlockEnd: spacingVars['--spacing-2'],
paddingInline: spacingVars['--spacing-2'],
- borderBottomLeftRadius: radiusVars['--radius-element'],
- borderBottomRightRadius: radiusVars['--radius-element'],
+ borderEndStartRadius: radiusVars['--radius-element'],
+ borderEndEndRadius: radiusVars['--radius-element'],
},
detached: {
marginTop: spacingVars['--spacing-1'],
@@ -216,7 +216,18 @@ export function FieldStatus({
{variant === 'detached' ? (
<span {...stylex.props(styles.detachedContent)}>
<span {...stylex.props(styles.detachedIcon)}>
- <Icon icon={statusIconMap[type]} size="sm" color="inherit" />
+ <Icon
+ icon={statusIconMap[type]}
+ size="sm"
+ color="inherit"
+ // Stable theme target on the detached message box's leading glyph
+ // itself, so a theme can restyle just this icon (color, size) —
+ // and each status — via `defineTheme`. Same-element rules in
+ // @layer astryx-theme win over the icon's own base
+ // width/height/fontSize, which a field-level target could not
+ // reach.
+ {...themeProps('field-status-icon', {type})}
+ />
</span>
<span>{message}</span>
</span>
diff --git a/packages/core/src/hooks/useInputStatusIcon.test.tsx b/packages/core/src/hooks/useInputStatusIcon.test.tsx
index a2a62de920..9923a76b30 100644
--- a/packages/core/src/hooks/useInputStatusIcon.test.tsx
+++ b/packages/core/src/hooks/useInputStatusIcon.test.tsx
@@ -160,3 +160,62 @@ describe('useInputStatusIcon — no dangling aria-describedby (WCAG 1.3.1)', ()
expectNoDanglingDescribedBy(container);
});
});
+
+describe('useInputStatusIcon — input-status-icon theme target', () => {
+ // The stable theme target lands on the on-field status glyph itself, so a
+ // theme can restyle (e.g. resize) just this icon via `defineTheme`. It is
+ // rendered by the attached and tooltip variants; detached suppresses the
+ // on-field icon in favour of the detached message box's leading glyph.
+ const getStatusIcon = (root: HTMLElement): HTMLElement => {
+ const icon = root.querySelector('.astryx-input-status-icon');
+ if (icon == null) {
+ throw new Error('status icon not found');
+ }
+ return icon as HTMLElement;
+ };
+
+ for (const variant of ['attached', 'tooltip'] as const) {
+ it(`renders the target on the on-field icon (statusVariant="${variant}")`, () => {
+ const {container} = render(
+ <TextInput
+ label="Field"
+ value=""
+ onChange={() => {}}
+ status={{type: 'warning', message: 'Message'}}
+ statusVariant={variant}
+ />,
+ );
+ const icon = getStatusIcon(container);
+ expect(icon).toHaveClass('astryx-input-status-icon');
+ expect(icon).toHaveClass('astryx-icon');
+ expect(icon).toHaveAttribute('data-size', 'md');
+ expect(icon).toHaveAttribute('data-status', 'warning');
+ });
+ }
+
+ it('reflects the status type per status', () => {
+ const {container} = render(
+ <TextInput
+ label="Field"
+ value=""
+ onChange={() => {}}
+ status={{type: 'success', message: 'Message'}}
+ statusVariant="attached"
+ />,
+ );
+ expect(getStatusIcon(container)).toHaveAttribute('data-status', 'success');
+ });
+
+ it('does not render the on-field target for the detached variant', () => {
+ const {container} = render(
+ <TextInput
+ label="Field"
+ value=""
+ onChange={() => {}}
+ status={{type: 'error', message: 'Message'}}
+ statusVariant="detached"
+ />,
+ );
+ expect(container.querySelector('.astryx-input-status-icon')).toBeNull();
+ });
+});
diff --git a/packages/core/src/hooks/useInputStatusIcon.tsx b/packages/core/src/hooks/useInputStatusIcon.tsx
index 0b1aa44cec..7b68ca5bf7 100644
--- a/packages/core/src/hooks/useInputStatusIcon.tsx
+++ b/packages/core/src/hooks/useInputStatusIcon.tsx
@@ -41,6 +41,7 @@ import type {InputStatus, InputStatusType} from '../Field/types';
import {useTooltip} from '../Tooltip';
import {useTranslator} from '../i18n';
import {colorVars, radiusVars} from '../theme/tokens.stylex';
+import {themeProps} from '../utils/themeProps';
/**
* Maps each status type to its glyph. Shared so every input shows the same icon
@@ -194,7 +195,17 @@ export function useInputStatusIcon({
}
const icon = (
- <Icon icon={STATUS_ICON[status.type]} size={size} color={status.type} />
+ <Icon
+ icon={STATUS_ICON[status.type]}
+ size={size}
+ color={status.type}
+ // Stable theme target on the status glyph itself, so a theme can restyle
+ // just this icon (color, size) — and each status — via `defineTheme`.
+ // Same-element rules in @layer astryx-theme win over the icon's own base
+ // width/height/fontSize, which a field-level target could not reach.
+ // Shared by the attached and tooltip variants across all bordered inputs.
+ {...themeProps('input-status-icon', {size, status: status.type})}
+ />
);
// Attached (and tooltip-without-message) variants: plain, non-interactive