Skip to content

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

TypeScript

fix(core): let string-mode Icon expose a meaningful icon (#3710)

Baraa Hamodic61dabb05804
diff --git a/.changeset/icon-meaningful.md b/.changeset/icon-meaningful.md
new file mode 100644
index 0000000000..2d5994865f
--- /dev/null
+++ b/.changeset/icon-meaningful.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Icon: allow string (registry) icons to be made meaningful. `aria-hidden="true"` is now applied before the prop spread, so consumers can override it (e.g. `aria-hidden={false}` + `role="img"` + `aria-label`) for a standalone informational icon. Previously registry-mode icons hardcoded `aria-hidden` after the spread, making it impossible to override — inconsistent with component-mode icons, which already allowed it. Default behavior (decorative, hidden) is unchanged. (#3710)
+@bhamodi
diff --git a/packages/core/src/Icon/Icon.test.tsx b/packages/core/src/Icon/Icon.test.tsx
index 562eaea6b1..6ae1ddff54 100644
--- a/packages/core/src/Icon/Icon.test.tsx
+++ b/packages/core/src/Icon/Icon.test.tsx
@@ -70,11 +70,7 @@ describe('Icon', () => {
'purple',
] as const;
const {rerender} = render(
- <Icon
- icon={HomeIcon}
- color={nonSemanticColors[0]}
- data-testid="icon"
- />,
+ <Icon icon={HomeIcon} color={nonSemanticColors[0]} data-testid="icon" />,
);
expect(screen.getByTestId('icon')).toBeInTheDocument();
@@ -108,12 +104,7 @@ describe('Icon', () => {
it('passes additional SVG props', () => {
render(
- <Icon
- icon={HomeIcon}
- data-testid="icon"
- role="img"
- aria-label="Home"
- />,
+ <Icon icon={HomeIcon} data-testid="icon" role="img" aria-label="Home" />,
);
const icon = screen.getByTestId('icon');
expect(icon).toHaveAttribute('role', 'img');
@@ -125,4 +116,25 @@ describe('Icon', () => {
// The component should render without errors with defaults
expect(screen.getByTestId('icon')).toBeInTheDocument();
});
+
+ it('applies aria-hidden by default in string (registry) mode', () => {
+ render(<Icon icon="check" data-testid="icon" />);
+ expect(screen.getByTestId('icon')).toHaveAttribute('aria-hidden', 'true');
+ });
+
+ it('lets a string-mode icon be made meaningful by overriding aria-hidden', () => {
+ render(
+ <Icon
+ icon="check"
+ data-testid="icon"
+ role="img"
+ aria-label="Done"
+ aria-hidden={false}
+ />,
+ );
+ const icon = screen.getByTestId('icon');
+ expect(icon).toHaveAttribute('role', 'img');
+ expect(icon).toHaveAttribute('aria-label', 'Done');
+ expect(icon).toHaveAttribute('aria-hidden', 'false');
+ });
});
diff --git a/packages/core/src/Icon/Icon.tsx b/packages/core/src/Icon/Icon.tsx
index 0eec6642aa..89bd9a9e44 100644
--- a/packages/core/src/Icon/Icon.tsx
+++ b/packages/core/src/Icon/Icon.tsx
@@ -281,12 +281,16 @@ function IconFromRegistry({
return (
<span
+ // Decorative by default, but placed BEFORE the prop spread so consumers
+ // can override it (e.g. `aria-hidden={false}` + `role="img"` +
+ // `aria-label`) to expose a meaningful standalone icon. This matches
+ // component-mode Icon, which already sets aria-hidden before its spread.
+ aria-hidden="true"
{...(spanProps as React.HTMLAttributes<HTMLSpanElement>)}
{...mergeProps(
themeProps('icon', {size, color}),
stylex.props(styles.span, colorStyles[color], spanSizeStyles[size]),
- )}
- aria-hidden="true">
+ )}>
{resolvedIcon}
</span>
);