From 35d85e069ebfef1b26ba181f443d9377a7bc003e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Denis=20Sl=C3=A1vik?= Date: Fri, 14 Oct 2022 16:00:26 +0200 Subject: [PATCH] feat(babel-preset): fix 'role' attribute on svg element for react native (#787) --- packages/babel-preset/src/index.test.ts | 2 +- packages/babel-preset/src/index.ts | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/babel-preset/src/index.test.ts b/packages/babel-preset/src/index.test.ts index 18945f50..5484aec6 100644 --- a/packages/babel-preset/src/index.test.ts +++ b/packages/babel-preset/src/index.test.ts @@ -213,7 +213,7 @@ describe('preset', () => { "import * as React from \\"react\\"; import Svg from \\"react-native-svg\\"; - const SvgComponent = props => ; + const SvgComponent = props => ; export default SvgComponent;" `) diff --git a/packages/babel-preset/src/index.ts b/packages/babel-preset/src/index.ts index 7a5b1b39..de8ec0ee 100644 --- a/packages/babel-preset/src/index.ts +++ b/packages/babel-preset/src/index.ts @@ -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) {