fix(accessibility): add alt text to PlatformIcon#239
Open
sentry-junior[bot] wants to merge 2 commits into
Open
fix(accessibility): add alt text to PlatformIcon#239sentry-junior[bot] wants to merge 2 commits into
sentry-junior[bot] wants to merge 2 commits into
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>
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>
Author
|
Fixed — the bot's concern was valid. When Also moved |
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.