Skip to content

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Rajdeepc
Copy link
Contributor

@Rajdeepc Rajdeepc commented Jun 4, 2025

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

  • New Property: Adds an isdecorative boolean property to <sp-avatar>.
    • When set to true:
      • The img element receives aria-hidden="true" and alt="".
      • The avatar is hidden from assistive technologies, following accessibility best practices for decorative images.
    • When false (default), the component expects a label for accessibility.
  • Warning for Missing Accessibility: If neither label nor isdecorative is set, a warning is logged to the console, guiding developers to supply a label or mark the avatar as decorative.
  • Story Updates: Storybook stories now include controls and an example for the isdecorative property.
  • Tests: Expanded and improved test coverage to verify:
    • Proper ARIA attributes for decorative and non-decorative avatars
    • Console warning when accessibility requirements are not met
    • Reflection of the isdecorative attribute

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

  • Added isdecorative property to <sp-avatar>
  • Updated rendering logic for ARIA attributes
  • Added Storybook example and controls for isdecorative
  • Improved unit tests for accessibility and attribute reflection
  • Added warning for missing label or 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

  • I have read the CONTRIBUTING and PULL_REQUESTS documents.
  • I have reviewed at the Accessibility Practices for this feature, see: Aria Practices
  • I have added automated tests to cover my changes.
  • I have included a well-written changeset if my change needs to be published.
  • I have included updated documentation if my change required it.

Reviewer's checklist

  • Includes a Github Issue with appropriate flag or Jira ticket number without a link
  • Includes thoughtfully written changeset if changes suggested include patch, minor, or major features
  • Automated tests cover all use cases and follow best practices for writing
  • Validated on all supported browsers
  • All VRTs are approved before the author can update Golden Hash

Manual review test cases

  • Descriptive Test Statement

    1. Go here
    2. Do this action
    3. Expect this result
  • Descriptive Test Statement

    1. Go here
    2. Do this action
    3. Expect this result

Device review

  • Did it pass in Desktop?
  • Did it pass in (emulated) Mobile?
  • Did it pass in (emulated) iPad?

Copy link

changeset-bot bot commented Jun 4, 2025

🦋 Changeset detected

Latest commit: 6f855e0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 84 packages
Name Type
@spectrum-web-components/avatar Minor
@spectrum-web-components/bundle Minor
documentation Patch
@spectrum-web-components/eslint-plugin Minor
@spectrum-web-components/accordion Minor
@spectrum-web-components/action-bar Minor
@spectrum-web-components/action-button Minor
@spectrum-web-components/action-group Minor
@spectrum-web-components/action-menu Minor
@spectrum-web-components/alert-banner Minor
@spectrum-web-components/alert-dialog Minor
@spectrum-web-components/asset Minor
@spectrum-web-components/badge Minor
@spectrum-web-components/breadcrumbs Minor
@spectrum-web-components/button-group Minor
@spectrum-web-components/button Minor
@spectrum-web-components/card Minor
@spectrum-web-components/checkbox Minor
@spectrum-web-components/clear-button Minor
@spectrum-web-components/close-button Minor
@spectrum-web-components/coachmark Minor
@spectrum-web-components/color-area Minor
@spectrum-web-components/color-field Minor
@spectrum-web-components/color-handle Minor
@spectrum-web-components/color-loupe Minor
@spectrum-web-components/color-slider Minor
@spectrum-web-components/color-wheel Minor
@spectrum-web-components/combobox Minor
@spectrum-web-components/contextual-help Minor
@spectrum-web-components/dialog Minor
@spectrum-web-components/divider Minor
@spectrum-web-components/dropzone Minor
@spectrum-web-components/field-group Minor
@spectrum-web-components/field-label Minor
@spectrum-web-components/help-text Minor
@spectrum-web-components/icon Minor
@spectrum-web-components/icons-ui Minor
@spectrum-web-components/icons-workflow Minor
@spectrum-web-components/icons Minor
@spectrum-web-components/iconset Minor
@spectrum-web-components/illustrated-message Minor
@spectrum-web-components/infield-button Minor
@spectrum-web-components/link Minor
@spectrum-web-components/menu Minor
@spectrum-web-components/meter Minor
@spectrum-web-components/modal Minor
@spectrum-web-components/number-field Minor
@spectrum-web-components/overlay Minor
@spectrum-web-components/picker-button Minor
@spectrum-web-components/picker Minor
@spectrum-web-components/popover Minor
@spectrum-web-components/progress-bar Minor
@spectrum-web-components/progress-circle Minor
@spectrum-web-components/radio Minor
@spectrum-web-components/search Minor
@spectrum-web-components/sidenav Minor
@spectrum-web-components/slider Minor
@spectrum-web-components/split-view Minor
@spectrum-web-components/status-light Minor
@spectrum-web-components/swatch Minor
@spectrum-web-components/switch Minor
@spectrum-web-components/table Minor
@spectrum-web-components/tabs Minor
@spectrum-web-components/tags Minor
@spectrum-web-components/textfield Minor
@spectrum-web-components/thumbnail Minor
@spectrum-web-components/toast Minor
@spectrum-web-components/tooltip Minor
@spectrum-web-components/top-nav Minor
@spectrum-web-components/tray Minor
@spectrum-web-components/underlay Minor
@spectrum-web-components/custom-vars-viewer Minor
@spectrum-web-components/story-decorator Minor
@spectrum-web-components/vrt-compare Minor
@spectrum-web-components/base Minor
@spectrum-web-components/grid Minor
@spectrum-web-components/opacity-checkerboard Minor
@spectrum-web-components/reactive-controllers Minor
@spectrum-web-components/shared Minor
@spectrum-web-components/styles Minor
@spectrum-web-components/theme Minor
@spectrum-web-components/truncated Minor
example-project-rollup Patch
example-project-webpack Patch

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

Copy link

github-actions bot commented Jun 4, 2025

Branch preview

Review the following VRT differences

When 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 current_golden_images_cache hash in the circleci config to accept the new images. Instructions are included in that file.
If the changes are unexpected, you can investigate the cause of the differences and update the code accordingly.

Copy link

github-actions bot commented Jun 4, 2025

Tachometer results

Chrome

avatar permalink

test-basic

Version Bytes Avg Time vs remote vs branch
npm latest 444 kB 18.80ms - 19.48ms - faster ✔
4% - 9%
0.74ms - 1.82ms
branch 422 kB 19.99ms - 20.85ms slower ❌
4% - 10%
0.74ms - 1.82ms
-
Firefox

avatar permalink

test-basic

Version Bytes Avg Time vs remote vs branch
npm latest 444 kB 41.82ms - 44.38ms - unsure 🔍
-8% - +2%
-3.48ms - +0.80ms
branch 422 kB 42.73ms - 46.15ms unsure 🔍
-2% - +8%
-0.80ms - +3.48ms
-

@Rajdeepc Rajdeepc marked this pull request as ready for review June 10, 2025 06:55
@Rajdeepc Rajdeepc requested a review from a team as a code owner June 10, 2025 06:55
Copy link
Contributor

@castastrophe castastrophe left a 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.

alt=${ifDefined(this.label || undefined)}
src=${this.src}
/>
<img class="image" alt=${this.label || ''} src=${this.src} />
Copy link
Contributor

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?

Copy link
Contributor

@rubencarvalho rubencarvalho Jun 10, 2025

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?

Copy link
Contributor

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)

Copy link
Contributor

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)

Copy link
Contributor

@rubencarvalho rubencarvalho left a 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)

@Rajdeepc Rajdeepc marked this pull request as draft June 11, 2025 11:36
@Rajdeepc Rajdeepc requested a review from jnurthen June 18, 2025 09:09
@Rajdeepc Rajdeepc self-assigned this Jun 18, 2025
@Rajdeepc Rajdeepc removed the request for review from jnurthen June 18, 2025 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: avatar should render an alt tag even if no label is specified to avoid a11y violations.
3 participants