Skip to content

Commit

Permalink
feat(babel-preset): fix 'role' attribute on svg element for react nat…
Browse files Browse the repository at this point in the history
…ive (#787)
  • Loading branch information
slavikdenis committed Oct 14, 2022
1 parent db35837 commit 35d85e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/babel-preset/src/index.test.ts
Expand Up @@ -213,7 +213,7 @@ describe('preset', () => {
"import * as React from \\"react\\";
import Svg from \\"react-native-svg\\";
const SvgComponent = props => <Svg a=\\"#000\\" b=\\"#fff\\" width={24} height={24} role=\\"img\\" {...props} />;
const SvgComponent = props => <Svg a=\\"#000\\" b=\\"#fff\\" width={24} height={24} accessibilityRole=\\"image\\" {...props} />;
export default SvgComponent;"
`)
Expand Down
13 changes: 9 additions & 4 deletions packages/babel-preset/src/index.ts
Expand Up @@ -50,10 +50,15 @@ function replaceMapToValues(replaceMap: { [key: string]: string }): Value[] {
const plugin = (_: ConfigAPI, opts: Options) => {
let toRemoveAttributes = ['version']
let toAddAttributes: Attribute[] = [
{
name: 'role',
value: 'img',
},
opts?.native === true
? {
name: 'accessibilityRole',
value: 'image',
}
: {
name: 'role',
value: 'img',
},
]

if (opts.svgProps) {
Expand Down

0 comments on commit 35d85e0

Please sign in to comment.