fix(accessibility): add alt text to PlatformIcon#239
Open
sentry-junior[bot] wants to merge 1 commit into
Open
Conversation
- 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 on lines
+328
to
+333
| <div | ||
| role="img" | ||
| aria-label={alt} | ||
| {...otherProps} | ||
| style={{ position: "relative", ...style }} | ||
| > |
There was a problem hiding this comment.
Bug: When withLanguageIcon is true, passing alt="" to mark an icon as decorative results in an inaccessible div with role="img" and an empty aria-label.
Severity: MEDIUM
Suggested Fix
When withLanguageIcon is true and alt is an empty string, conditionally set role="presentation" or role="none" on the div instead of role="img". This will correctly remove the element from the accessibility tree, aligning its behavior with a native <img alt=""> and ensuring it is treated as purely decorative.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: src/platformIcon.tsx#L328-L333
Potential issue: When the `PlatformIcon` component is used with the
`withLanguageIcon={true}` prop, it fails to correctly handle decorative images. If a
caller passes `alt=""` to mark the icon as decorative, the component renders a `<div
role="img" aria-label="">`. Unlike a standard `<img alt="">`, this combination is not
consistently treated as decorative by screen readers. This leaves an element with an
empty accessible name in the accessibility tree, leading to unreliable behavior for
users of assistive technology and contradicting the component's documented contract for
handling decorative icons.
Did we get this right? 👍 / 👎 to inform future reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds accessible labels to all
PlatformIconrender paths.Changes
Normal render (
<img>):altprop to thePropstype (note:altlives onImgHTMLAttributes, notHTMLAttributes, so it wasn't passable before)altto theplatformprop value so every icon has a meaningful label without callers needing to change anythingalt=""to explicitly mark the icon as decorative when it accompanies visible textWith-language-icon render (composite
<div>+ two<img>s):divwithrole="img"andaria-label={alt}(ARIA composite image pattern)<img>s getalt=""since the parent element is now the accessible entry pointInvestigation notes
ContextIcon(ingetsentry/sentryatstatic/app/components/events/contexts/contextIcon.tsx) wrapsPlatformIconand doesn't passalt. With this change it will inheritalt={platformIconName ?? 'default'}automatically — passable but not ideal. A follow-up in that repo could passalt={name}(the original context name like"android"or"firefox") for more meaningful labels.Verification
tsc --noEmitpasses clean.View Session in Sentry
Action taken on behalf of Ryan Albrecht.