-
Notifications
You must be signed in to change notification settings - Fork 233
fix(avatar): Avatar component now always includes alt attribute #5512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 6f855e0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 84 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Branch previewReview the following VRT differencesWhen a visual regression test fails (or has previously failed while working on this branch), its results can be found in the following URLs:
If the changes are expected, update the |
Tachometer resultsChromeavatar permalinktest-basic
Firefoxavatar permalinktest-basic
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but I think we're missing an opportunity to inform customers of an important accessibility improvement they can make by reporting this missing content in dev mode.
packages/avatar/src/Avatar.ts
Outdated
alt=${ifDefined(this.label || undefined)} | ||
src=${this.src} | ||
/> | ||
<img class="image" alt=${this.label || ''} src=${this.src} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to surface a dev-mode warning that alt text is missing and that the image will be skipped by screen readers if not provided?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having an empty alt
attribute is acceptable for decorative avatars, so I'm afraid flagging it may just add console noise for valid use cases. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(e.g., the profile picture avatar in Adobe Home is decorative)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's discuss, because the A11Y team also has concerns: #5513 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revoking my approval for further discussion, after this comment:
#5513 (comment)
* When false and no label is provided, a warning will be logged. | ||
*/ | ||
@property({ type: Boolean, reflect: true }) | ||
public isdecorative = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: two-word property names are usually camelCase and then surfaced as kebab case attributes, as in isDecorative
and is-decorative
I would recommend naming this either with the property and attribute name decorative
.
class="image" | ||
alt=${ifDefined(this.label || undefined)} | ||
alt=${ifDefined(this.isdecorative ? '' : this.label)} | ||
aria-hidden=${this.isdecorative ? 'true' : 'false'} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the avatar is keyboard navigable it should not be hidden from a screenreader.
aria-hidden=${this.isdecorative ? 'true' : 'false'} | |
aria-hidden=${this.isdecorative && !this.href ? 'true' : 'false'} |
// Log a warning if neither label nor isdecorative is set | ||
if (!this.label && !this.isdecorative) { | ||
window.__swc.warn( | ||
this, | ||
`<${this.localName}> is missing a label and is not marked as decorative. Either provide a label or set isdecorative="true" for accessibility.`, | ||
'https://opensource.adobe.com/spectrum-web-components/components/avatar/#accessibility', | ||
{ | ||
type: 'accessibility', | ||
} | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Log a warning if neither label nor isdecorative is set | |
if (!this.label && !this.isdecorative) { | |
window.__swc.warn( | |
this, | |
`<${this.localName}> is missing a label and is not marked as decorative. Either provide a label or set isdecorative="true" for accessibility.`, | |
'https://opensource.adobe.com/spectrum-web-components/components/avatar/#accessibility', | |
{ | |
type: 'accessibility', | |
} | |
); | |
} | |
if (!this.label) { | |
if(this.href) { | |
// Log a warning if avatar is a link but has no label | |
window.__swc.warn( | |
this, | |
`<${this.localName}> is has a link but no label. To fix this issue, provide a label.`, | |
'https://opensource.adobe.com/spectrum-web-components/components/avatar/#accessibility', | |
{ | |
type: 'accessibility', | |
} | |
); | |
} else if(!this.isdecorative) { | |
// Log a warning if neither label nor isdecorative is set | |
window.__swc.warn( | |
this, | |
`<${this.localName}> is missing a label and is not marked as decorative. Either provide a label or set isdecorative="true" for accessibility.`, | |
'https://opensource.adobe.com/spectrum-web-components/components/avatar/#accessibility', | |
{ | |
type: 'accessibility', | |
} | |
); | |
} | |
} |
- When a `label` is provided, it is used as the `alt` text for the image | ||
- When `isdecorative` is true, the avatar is hidden from screen readers using `aria-hidden="true"` | ||
- The component maintains focus management for keyboard navigation | ||
- Color contrast meets WCAG 2.1 Level AA requirements |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- When a `label` is provided, it is used as the `alt` text for the image | |
- When `isdecorative` is true, the avatar is hidden from screen readers using `aria-hidden="true"` | |
- The component maintains focus management for keyboard navigation | |
- Color contrast meets WCAG 2.1 Level AA requirements | |
- When a `label` is provided, it is used as the `alt` text for the image | |
- When the avatar has an `href`, the `label` serves as link text | |
- When `isdecorative` is true, the avatar is hidden from screen readers using `aria-hidden="true"` | |
- The component maintains focus management for keyboard navigation | |
- Color contrast meets WCAG 2.1 Level AA requirements |
### Accessibility Best Practices | ||
|
||
- Always provide a `label` for avatars that represent users or have meaningful content | ||
- Use `isdecorative` for purely decorative avatars |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Use `isdecorative` for purely decorative avatars | |
- Use `isdecorative` for purely avatars that do not have an `href` and are purely decorative |
|
||
### Accessibility Best Practices | ||
|
||
- Always provide a `label` for avatars that represent users or have meaningful content |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Always provide a `label` for avatars that represent users or have meaningful content | |
- Always provide a `label` for avatars that represent users, have meaningful content, or act as links |
Description
This PR enhances the
<sp-avatar>
component to improve accessibility, particularly for decorative avatars. The update introduces a new property, isdecorative, and updates the rendering and accessibility logic for avatars used purely for decoration.Key Changes
<sp-avatar>
.Motivation
Some avatars are decorative and should not be announced by screen readers. This change allows consumers of
<sp-avatar>
to explicitly mark avatars as decorative, ensuring correct ARIA attributes are applied and accessibility warnings are surfaced during development.Related Links
Checklist
isdecorative
property to<sp-avatar>
isdecorative
isdecorative
Let me know if you want this tailored further, or if you have a specific template you’d like me to use!
Related issue(s)
Screenshots (if appropriate)
Author's checklist
Reviewer's checklist
patch
,minor
, ormajor
featuresManual review test cases
Descriptive Test Statement
Descriptive Test Statement
Device review