Skip to content

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

TypeScript

fix(TextArea, TextInput): the start icon slot follows the shared presence check (#9443)

Cindy Zhang99b8ede255f1
diff --git a/.changeset/start-icon-slot-presence.md b/.changeset/start-icon-slot-presence.md
new file mode 100644
index 0000000000..e810ce3e5a
--- /dev/null
+++ b/.changeset/start-icon-slot-presence.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] TextArea: a `startIcon` of `0` showed a stray "0" beside the start-icon slot, with no padding reserved for it. The slot and its padding now follow one presence check: empty values (`null`, `false`, `''`) render no slot, and `0` renders inside the slot like any other content. TextInput uses the same check, with no visible change.
+
+@cixzhang
diff --git a/packages/core/src/TextArea/TextArea.test.tsx b/packages/core/src/TextArea/TextArea.test.tsx
index 31da107519..f696e3aae6 100644
--- a/packages/core/src/TextArea/TextArea.test.tsx
+++ b/packages/core/src/TextArea/TextArea.test.tsx
@@ -283,6 +283,57 @@ describe('TextArea', () => {
expect(container.querySelector('svg')).not.toBeInTheDocument();
});
+ // One presence check decides the start icon's slot and its padding
+ // (architecture:react-component-runtime INV16): empty values render no
+ // slot, and 0 is content shown inside the slot, never a stray "0" beside it.
+ describe('start icon slot presence', () => {
+ const zeroTextParent = (container: HTMLElement) => {
+ const walker = document.createTreeWalker(container, NodeFilter.SHOW_TEXT);
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {
+ if (node.textContent === '0') {
+ return node.parentElement;
+ }
+ }
+ return null;
+ };
+
+ it.each([
+ ['null', null],
+ ['false', false],
+ ['an empty string', ''],
+ ])('renders no slot and reserves no padding for %s', (_label, value) => {
+ const {container} = render(
+ <TextArea
+ label="Description"
+ value=""
+ onChange={() => {}}
+ startIcon={value}
+ />,
+ );
+ expect(container.querySelector('[class*="startIcon"]')).toBeNull();
+ expect(screen.getByRole('textbox').className).not.toContain(
+ 'textareaWithStartIcon',
+ );
+ });
+
+ it('shows 0 inside the slot, with its padding, not beside it', () => {
+ const {container} = render(
+ <TextArea
+ label="Description"
+ value=""
+ onChange={() => {}}
+ startIcon={0}
+ />,
+ );
+ const parent = zeroTextParent(container);
+ expect(parent).not.toBeNull();
+ expect(parent?.className).toContain('startIcon');
+ expect(screen.getByRole('textbox').className).toContain(
+ 'textareaWithStartIcon',
+ );
+ });
+ });
+
describe('status prop', () => {
it('renders with error status icon', () => {
const {container} = render(
diff --git a/packages/core/src/TextArea/TextArea.tsx b/packages/core/src/TextArea/TextArea.tsx
index 2aed0d3025..09bcac7f18 100644
--- a/packages/core/src/TextArea/TextArea.tsx
+++ b/packages/core/src/TextArea/TextArea.tsx
@@ -43,6 +43,7 @@ import {
inputStatusFocusWithinStyles,
} from '../Field';
import {Icon, renderIconSlot, type IconType} from '../Icon';
+import {isRenderable} from '../utils/isRenderable';
import {Spinner} from '../Spinner';
import {useTooltip} from '../Tooltip';
import {mergeProps} from '../utils';
@@ -433,6 +434,10 @@ export function TextArea({
containerStyle,
});
const size = useSize(sizeProp, 'md');
+ // One presence check for the start icon's slot and its padding
+ // (`architecture:react-component-runtime` INV16), on the value the caller
+ // passed: an icon component counts as present, as any non-empty value does.
+ const hasStartIcon = isRenderable(startIcon as ReactNode);
const t = useComponentTranslator();
const isEffectivelyRequired = useResolvedRequired({isRequired, isOptional});
const announce = useAnnounce();
@@ -628,7 +633,7 @@ export function TextArea({
controlClassName,
controlStyle,
)}>
- {startIcon && (
+ {hasStartIcon && (
<span {...stylex.props(styles.startIcon)}>
{renderIconSlot(startIcon, {size: 'sm', color: 'secondary'})}
</span>
@@ -679,7 +684,7 @@ export function TextArea({
styles.textarea,
textareaSizeStyles[size],
isDisabled && styles.textareaDisabled,
- Boolean(startIcon) && styles.textareaWithStartIcon,
+ hasStartIcon && styles.textareaWithStartIcon,
// Reserve trailing space only when the end slot actually renders
// something (spinner or on-field status icon). The `detached`
// status variant suppresses the on-field icon — its glyph lives
diff --git a/packages/core/src/TextInput/TextInput.test.tsx b/packages/core/src/TextInput/TextInput.test.tsx
index 317b67cc11..ea0a66fe4d 100644
--- a/packages/core/src/TextInput/TextInput.test.tsx
+++ b/packages/core/src/TextInput/TextInput.test.tsx
@@ -246,6 +246,21 @@ describe('TextInput', () => {
expect(container.querySelector('svg')).not.toBeInTheDocument();
});
+ // The shared presence check decides the start icon's slot
+ // (architecture:react-component-runtime INV16).
+ it.each([
+ ['null', null],
+ ['false', false],
+ ['an empty string', ''],
+ ])('renders no start icon for %s', (_label, value) => {
+ const {container} = render(
+ <TextInput label="Name" value="" onChange={() => {}} startIcon={value} />,
+ );
+ const wrapper = screen.getByRole('textbox').parentElement as HTMLElement;
+ expect(wrapper.firstChild).toBe(screen.getByRole('textbox'));
+ expect(container.querySelector('svg')).toBeNull();
+ });
+
describe('status prop', () => {
it('renders with error status icon', () => {
const {container} = render(
diff --git a/packages/core/src/TextInput/TextInput.tsx b/packages/core/src/TextInput/TextInput.tsx
index a8abae4963..7658363724 100644
--- a/packages/core/src/TextInput/TextInput.tsx
+++ b/packages/core/src/TextInput/TextInput.tsx
@@ -44,6 +44,7 @@ import {
inputStatusFocusWithinStyles,
} from '../Field';
import {renderIconSlot, type IconType} from '../Icon';
+import {isRenderable} from '../utils/isRenderable';
import {Spinner} from '../Spinner';
import {useTooltip} from '../Tooltip';
import {VisuallyHidden} from '../VisuallyHidden';
@@ -493,7 +494,11 @@ export function TextInput({
controlClassName,
controlStyle,
)}>
- {startIcon && renderIconSlot(startIcon, {size: 'sm', color: 'secondary'})}
+ {/* The shared presence check decides the slot
+ (`architecture:react-component-runtime` INV16); an icon component
+ counts as present, as any non-empty value does. */}
+ {isRenderable(startIcon as ReactNode) &&
+ renderIconSlot(startIcon, {size: 'sm', color: 'secondary'})}
{inputGroup && <VisuallyHidden id={inputLabelID}>{label}</VisuallyHidden>}
<input
{...fieldProps}