Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lemon-lizards-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': patch
---

Added support for `Avatar` being presentational
8 changes: 5 additions & 3 deletions polaris-react/src/components/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ export function Avatar({
label = i18n.translate('Polaris.Avatar.labelWithInitials', {
initials: splitInitials,
});
} else {
label = i18n.translate('Polaris.Avatar.label');
}

const className = classNames(
Expand Down Expand Up @@ -175,7 +173,11 @@ export function Avatar({
);

return (
<span aria-label={label} role="img" className={className}>
<span
aria-label={label}
role={label ? 'img' : 'presentation'}
className={className}
>
{svgMarkup}
{imageMarkUp}
</span>
Expand Down
18 changes: 18 additions & 0 deletions polaris-react/src/components/Avatar/tests/Avatar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,22 @@ describe('<Avatar />', () => {
});
});
});

describe('accessibilityRole', () => {
it('is presentation role if name, initials, or accessibilityLabel not passed', () => {
const avatar = mountWithApp(<Avatar />);

expect(avatar).toContainReactComponent('span', {
role: 'presentation',
});
});

it('is img role if name passed', () => {
const avatar = mountWithApp(<Avatar name="Hello World" />);

expect(avatar).toContainReactComponent('span', {
role: 'img',
});
});
});
});