mui / mui/material-ui

[SvgIcon] `titleAccess` prop not working properly in conjunction with`component` prop

Open
#33,421 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

component: SvgIcon scope: icons type: bug
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

Duplicates
  • I have searched the existing issues
Latest version
  • I have tested the latest version
Current behavior 😯

When I use the SvgIcon with component prop like:

<SvgIcon
  component={MySvgIcon}
  titleAccess="My title"
/>

the aria-hidden="true" is removed and role="img" added, but there is no <title>My title</title> tag added to the svg

Expected behavior 🤔

titleAccess prop should add the <title>my title here</title> tag to the SVG element.

Steps to reproduce 🕹

Steps:

  1. Import custom SVG icon using webpack svgr plugin as ReactComponent"
import { ReactComponent as StarIcon } from './star.svg';
  1. Use the imported SVG in the component prop in SvgIcon component with titleAccess
<SvgIcon
  component={StarIcon}
  titleAccess="My title"
/>
Context 🔦

I want to use my custom SVG icons with the Material UI SvgIcon component and make it fully accessible.

Your environment 🌎
System: OS: macOS 12.4 Binaries: Node: 16.14.0 - ~/.nvm/versions/node/v16.14.0/bin/node Yarn: 1.22.17 - ~/.nvm/versions/node/v16.14.0/bin/yarn npm: 8.10.0 - ~/work/PWA-Framework/node_modules/.bin/npm Browsers: Chrome: 103.0.5060.114 Edge: Not Found Firefox: 98.0.2 Safari: 15.5 npmPackages: @emotion/styled: 10.3.0 @types/react: 18.0.1 => 18.0.1 react: 18.0.0 => 18.0.0 react-dom: 18.0.0 => 18.0.0 styled-components: 5.3.5 => 5.3.5 typescript: 4.4 => 4.4.4

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the SvgIcon component's handling of titleAccess and the component prop, then reproduce the case with a custom ReactComponent imported from star.svg. Done means the rendered SVG includes a <title>My title</title> while retaining the expected accessible role and aria behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
accessibility, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.