Skip to content

fix(icon)!: keep aria-hidden on inline SVG icons - #3262

Merged
interactivellama merged 2 commits into
salesforce:masterfrom
zigzagdev:fix/utility-icon-inline-aria-hidden
Oct 29, 2026
Merged

interactivellama merged 2 commits into
salesforce:masterfrom
zigzagdev:fix/utility-icon-inline-aria-hidden

Conversation

@zigzagdev

@zigzagdev zigzagdev commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #

Additional description

Summary

Icons rendered from inline SVG data (the icon prop) now keep aria-hidden="true" on the <svg>, therefore screen readers no longer expose the decorative icon as an unnamed image.

Motivation

Icon, ButtonIcon and InputIcon all pass aria-hidden to UtilityIcon, because the icon is decorative and its meaning is carried by assistive text.
When UtilityIcon renders inline SVG data, that attribute never reached the <svg>.
As a result the accessibility tree exposed an extra unnamed img node next to the assistive text, and some screen readers announce it.
The committed story snapshot Icon > BaseImported already showed the missing attribute.
This is a regression from the rewrite. The pre-rewrite implementation passed every remaining prop to Svg, including aria-hidden.

What I have done

  • UtilityIcon has two render paths. The sprite path spreads the remaining props onto <svg>, so it keeps aria-hidden. The inline path only forwarded className and style to Svg and discarded the rest, which is the root cause. It now also forwards aria-hidden, which Svg already supports.
  • Added a regression test that renders Icon with the icon prop and asserts the <svg> has aria-hidden="true".
  • Regenerated the Icon > BaseImported story snapshot. Its only change is the added attribute.
  • The style commit only contains Prettier output from the pre commit hook for the two touched files, kept separate so the functional diff stays small.

Test Results

before
スクリーンショット 2026-10-28 9 31 07

after
スクリーンショット 2026-10-28 9 30 24


CONTRIBUTOR checklist (do not remove)

Please complete for every pull request.

Green gate — all of these must pass locally (CI runs the same):

  • npm run lint passes with 0 errors (npm run lint:fix to auto-fix). Warnings are the tracked gradual-migration backlog; do not add new errors.
  • npm run typecheck is clean (tsc --noEmit).
  • npm test -- --run passes — this runs both Vitest projects (jsdom unit + real-browser browser) and the story HTML snapshots. If you changed rendered markup on purpose, update snapshots with npm test -- --run -u and review the diff.
  • npm run build succeeds (type-check + Vite library build + .d.ts + entry shims).

Behavior & docs:

  • First-time contributors: sign the CLA (a bot will comment with instructions).
  • Added/updated Vitest + React Testing Library tests for the change (template: components/button/__tests__). New props and bug fixes should get a regression test. Tests that genuinely need a real browser (focus traversal, layout/measurement, canvas) go in a *.browser.test.jsx file (the browser project); everything else is jsdom.
  • Reviewed the component's Storybook stories: npm run storybook → http://localhost:6007/. Confirm the story actually renders and behaves (deprecated Storyshots/Karma are gone; there is no separate browser-tests server).
  • Story/example code uses the component's real prop API (e.g. render-props like onRenderContent / onRenderVisualPicker, icon props, events), not assumptions — a common source of "component looks broken" reports has been stories authored against the wrong API. Cross-check against components/<name>/__examples__.
  • Storybook Accessibility (a11y) panel shows no new violations for the affected stories.
  • If you added or changed a type, remember runtime PropTypes were removed in the TS migration — types are the contract. Ship accurate .d.ts (they're generated by the build); JS consumers rely on them via editor type-acquisition.

REVIEWER checklist (do not remove)

  • CI is green (GitHub Actions CI workflow: lint, typecheck, test, build). Chromatic visual review, if configured, has been checked.
  • Change has adequate test coverage; bug fixes include a regression test.
  • Reviewed the affected Storybook stories and their a11y panels.
  • Rendered markup still conforms to SLDS — check the story HTML snapshot diff (components/__tests__/__snapshots__/story-snapshots.test.jsx.snap).
  • Public API / package surface: if exports changed, the deep-import contract still holds (@salesforce/design-system-react/components/<name> and nested paths resolve for ESM, CJS, and types). Removing/renaming a public component or export is a breaking change → feat!:/BREAKING CHANGE: and a major version bump.

UtilityIcon rendered inline SVG data (the `icon` prop) with only
className and style, so the aria-hidden passed by Icon, ButtonIcon and
InputIcon never reached the svg. Screen readers could expose the
decorative icon as an unnamed image. Pass aria-hidden through to Svg as
the pre-rewrite implementation did and add a regression test.
@zigzagdev zigzagdev changed the title fix(icon): keep aria-hidden on inline SVG icons fix(icon)!: keep aria-hidden on inline SVG icons Oct 28, 2026
@interactivellama
interactivellama merged commit dcd7ec9 into salesforce:master Oct 29, 2026
7 checks passed
@zigzagdev
zigzagdev deleted the fix/utility-icon-inline-aria-hidden branch October 29, 2026 23:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants