fix: pass image alt text to SVG images for accessibility - #1089
Open
afonsograca wants to merge 1 commit into
Open
fix: pass image alt text to SVG images for accessibility#1089afonsograca wants to merge 1 commit into
afonsograca wants to merge 1 commit into
Conversation
SVG images rendered via MDSvg always fell back to its default "image" label, so screen readers announced nothing useful for `.svg` URIs — including those wrapped in a link through linkImage. Forward the markdown alt text (falling back to the title) as MDImage already does.
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.
As a screen reader user, I should hear the alt text of an SVG image. Raster images already do this. The markdown
must announce "Company logo". It must not announce only the word "image". This must also work when a link contains the image.In this PR we send the alt text to
MDSvg:Renderer.image()now givesalt={alt || title}toMDSvg. TheMDImagebranch below it does the same.MDSvgalready accepts this prop, and setsaria-labelandaccessibilityLabel. No code gave the prop a value. Each.svgURI used the default label"image".Renderer.linkImage()callsimage(). Linked SVGs get the same correction.title.fetchwith a mock.MDSvgthen loads the file and showsSvgFromXml. Without the mock, the component stops in the error state, and the element with the label does not appear. This is why the old SVG snapshots show an emptyView.Markdown.spec.tsx.snapget the newaltprop. No other snapshot changes.We believe it is better to use the existing prop than to change the default label of
MDSvg. This keeps the order of alt and title in one place, and makes the two image paths the same.