Skip to content

Commit 35d85e0

Browse files
authoredOct 14, 2022
feat(babel-preset): fix 'role' attribute on svg element for react native (#787)
1 parent db35837 commit 35d85e0

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed
 

‎packages/babel-preset/src/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ describe('preset', () => {
213213
"import * as React from \\"react\\";
214214
import Svg from \\"react-native-svg\\";
215215
216-
const SvgComponent = props => <Svg a=\\"#000\\" b=\\"#fff\\" width={24} height={24} role=\\"img\\" {...props} />;
216+
const SvgComponent = props => <Svg a=\\"#000\\" b=\\"#fff\\" width={24} height={24} accessibilityRole=\\"image\\" {...props} />;
217217
218218
export default SvgComponent;"
219219
`)

‎packages/babel-preset/src/index.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,15 @@ function replaceMapToValues(replaceMap: { [key: string]: string }): Value[] {
5050
const plugin = (_: ConfigAPI, opts: Options) => {
5151
let toRemoveAttributes = ['version']
5252
let toAddAttributes: Attribute[] = [
53-
{
54-
name: 'role',
55-
value: 'img',
56-
},
53+
opts?.native === true
54+
? {
55+
name: 'accessibilityRole',
56+
value: 'image',
57+
}
58+
: {
59+
name: 'role',
60+
value: 'img',
61+
},
5762
]
5863

5964
if (opts.svgProps) {

0 commit comments

Comments
 (0)
Please sign in to comment.