File tree Expand file tree Collapse file tree 1 file changed +18
-5
lines changed
packages/sui-svg/templates Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -2,11 +2,24 @@ const template = content => {
2
2
return `import {memo} from 'react'
3
3
import AtomIcon from '@s-ui/react-atom-icon'
4
4
5
- const MemoAtomIcon = memo(props =>
6
- <AtomIcon {...props}>
7
- <span dangerouslySetInnerHTML={{ __html: '${ content } ' }} />
8
- </AtomIcon>
9
- )
5
+ const injectAccessibility = ({id, svg, title}) => {
6
+ if (!title || !id) return svg.replace(/<svg([^>]*)>/, '<svg$1 aria-hidden="true">')
7
+
8
+ return svg.replace(
9
+ /<svg([^>]*)>/,
10
+ \`<svg$1 role="img" aria-labelledby="\${id}"><title id="\${id}">\${title}</title>\`
11
+ )
12
+ }
13
+
14
+ const MemoAtomIcon = memo(({id, title, ...props}) => {
15
+ const safeContent = injectAccessibility({id, svg: \`${ content } \`, title})
16
+
17
+ return (
18
+ <AtomIcon {...props}>
19
+ <span dangerouslySetInnerHTML={{__html: safeContent}} />
20
+ </AtomIcon>
21
+ )
22
+ })
10
23
11
24
MemoAtomIcon.displayName = 'AtomIcon'
12
25
You can’t perform that action at this time.
0 commit comments