An open source design system that's fully customizable and agent ready
TypeScript
fix(thumbnail): use group role for aria-label to satisfy aria-prohibited-attr (#3535)
Cindy Zhangeae28724b075
diff --git a/.changeset/thumbnail-aria-label-role.md b/.changeset/thumbnail-aria-label-role.mdnew file mode 100644index 0000000000..da1d9b0dc6--- /dev/null+++ b/.changeset/thumbnail-aria-label-role.md@@ -0,0 +1,6 @@+---+'@astryxdesign/core': patch+---++[fix] Thumbnail: give the labeled root a group role so its accessible name is valid. Previously the file name was set via aria-label on a plain div with no role, which axe flags as aria-prohibited-attr (serious) because a generic element cannot carry a name. (#3343)+@cixzhangdiff --git a/packages/core/src/Thumbnail/Thumbnail.test.tsx b/packages/core/src/Thumbnail/Thumbnail.test.tsxindex 2d51e8f134..bf1ca6ba6b 100644--- a/packages/core/src/Thumbnail/Thumbnail.test.tsx+++ b/packages/core/src/Thumbnail/Thumbnail.test.tsx@@ -37,11 +37,45 @@ describe('Thumbnail', () => {expect(screen.getByRole('status')).toBeInTheDocument();});- it('uses label as accessible name on root', () => {+ it('exposes the label as an accessible name via a valid group role', () => {render(<Thumbnail label="photo.png" data-testid="thumb" />);- expect(screen.getByTestId('thumb')).toHaveAttribute('aria-label', 'photo.png');+ // The accessible name must be carried by a valid named role (group),+ // not by a bare aria-label on a generic div (aria-prohibited-attr).+ const group = screen.getByRole('group', {name: 'photo.png'});+ expect(group).toBe(screen.getByTestId('thumb'));});+ it('does not put aria-label on a generic (roleless) element', () => {+ render(<Thumbnail label="photo.png" data-testid="thumb" />);+ const thumb = screen.getByTestId('thumb');+ // The labeled element must declare a role so the name is legitimate.+ expect(thumb).toHaveAttribute('role', 'group');+ });++ it('keeps interactive children accessible while exposing the group name', () => {+ const onRemove = vi.fn();+ render(+ <Thumbnail+ src="/img.jpg"+ alt="Clickable"+ label="file.png"+ onClick={vi.fn()}+ onRemove={onRemove}+ />,+ );+ // A group role (unlike img) must not hide descendant controls.+ expect(+ screen.getByRole('group', {name: 'file.png — Clickable'}),+ ).toBeInTheDocument();+ expect(+ screen.getByRole('button', {name: 'Open file.png — Clickable'}),+ ).toBeInTheDocument();+ expect(+ screen.getByRole('button', {name: 'Remove file.png — Clickable'}),+ ).toBeInTheDocument();+ });++it('label is shown via tooltip, not as inline text', () => {render(<Thumbnail label="photo.png" data-testid="thumb" />);// Label should exist in DOM (tooltip) but not as a direct child text nodediff --git a/packages/core/src/Thumbnail/Thumbnail.tsx b/packages/core/src/Thumbnail/Thumbnail.tsxindex b4e59d1aba..a7d4d8662a 100644--- a/packages/core/src/Thumbnail/Thumbnail.tsx+++ b/packages/core/src/Thumbnail/Thumbnail.tsx@@ -58,8 +58,9 @@ export interface ThumbnailProps extends BaseProps<HTMLDivElement> {alt?: string;/*** Accessible label for the thumbnail (e.g. file name).- * Not rendered visually — shown in a tooltip on hover and used- * as accessible name for the remove button.+ * Not rendered visually — shown in a tooltip on hover, exposed as the+ * accessible name of the thumbnail group, and used as the accessible+ * name for the remove button.*/label?: string;/**@@ -296,6 +297,7 @@ export function Thumbnail({<divref={ref}data-testid={testId}+ role="group"aria-label={accessibleName}{...mergeProps(themeProps('thumbnail'),