Skip to content

fix(accessibility): add alt text to PlatformIcon#239

Open
sentry-junior[bot] wants to merge 2 commits into
masterfrom
fix/accessibility-alt-attributes
Open

fix(accessibility): add alt text to PlatformIcon#239
sentry-junior[bot] wants to merge 2 commits into
masterfrom
fix/accessibility-alt-attributes

Conversation

@sentry-junior
Copy link
Copy Markdown

@sentry-junior sentry-junior Bot commented May 26, 2026

What

Adds accessible labels to all PlatformIcon render paths.

Changes

Normal render (<img>):

  • Adds an explicit alt prop to the Props type (note: alt lives on ImgHTMLAttributes, not HTMLAttributes, so it wasn't passable before)
  • Defaults alt to the platform prop value so every icon has a meaningful label without callers needing to change anything
  • Callers can pass alt="" to explicitly mark the icon as decorative when it accompanies visible text

With-language-icon render (composite <div> + two <img>s):

  • Wraps the two images in a div with role="img" and aria-label={alt} (ARIA composite image pattern)
  • Both inner <img>s get alt="" since the parent element is now the accessible entry point

Investigation notes

ContextIcon (in getsentry/sentry at static/app/components/events/contexts/contextIcon.tsx) wraps PlatformIcon and doesn't pass alt. With this change it will inherit alt={platformIconName ?? 'default'} automatically — passable but not ideal. A follow-up in that repo could pass alt={name} (the original context name like "android" or "firefox") for more meaningful labels.

Verification

tsc --noEmit passes clean.


View Session in Sentry

Action taken on behalf of Ryan Albrecht.

- Add explicit `alt` prop to Props type (HTMLAttributes doesn't include it since that's ImgHTMLAttributes)
- Default alt to the platform name so icons are identifiable by screen readers out of the box
- Pass alt="" to mark icons as decorative when caller opts in
- For withLanguageIcon variant: wrap imgs in a div with role="img" and aria-label, inner imgs get alt="" (composite image pattern)
- Document the escape hatch: pass alt="" explicitly to declare the icon decorative

Co-authored-by: Ryan Albrecht <ryan@sentry.io>
Comment thread src/platformIcon.tsx
When alt="" is passed to the withLanguageIcon variant, use role="none"
instead of role="img" aria-label="". An empty aria-label on a role="img"
element is not reliably treated as decorative by screen readers; role="none"
(equivalent to role="presentation") correctly removes the element from
the accessibility tree, matching the behavior of a native <img alt="">.

Also move role/aria-label after {...otherProps} so they always take effect
and cannot be accidentally overridden by callers.

Co-authored-by: Ryan Albrecht <ryan@sentry.io>
@sentry-junior
Copy link
Copy Markdown
Author

sentry-junior Bot commented May 26, 2026

Fixed — the bot's concern was valid. When alt="" is passed on the withLanguageIcon path, the div now gets role="none" (no aria-label) instead of role="img" aria-label="". That matches the behavior of a native <img alt=""> — the element is fully removed from the accessibility tree.

Also moved role/aria-label after {...otherProps} so they can't be accidentally overridden by callers.

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.

0 participants