Skip to content

Commit 19ddeb3

Browse files
committed
fix(WCAG): correctly read aria-label and ensure aria-hidden is false when label present
1 parent 1c3c19a commit 19ddeb3

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
"homepage": "https://github.com/FortAwesome/react-fontawesome",
2020
"repository": {
2121
"type": "git",
22-
"url": "https://github.com/FortAwesome/react-fontawesome.git"
22+
"url": "git+https://github.com/FortAwesome/react-fontawesome.git"
23+
},
24+
"bugs": {
25+
"url": "https://github.com/FortAwesome/react-fontawesome/issues"
2326
},
2427
"contributors": [
2528
"Travis Chase <travis@fontawesome.com>",

src/converter.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,6 @@ export function convert(
9898
attrs.style = styleToObject(String(val))
9999
break
100100
}
101-
case key === 'aria-label': {
102-
attrs['aria-label'] = val
103-
attrs['aria-hidden'] = 'false' // Set aria-hidden to false when aria-label has a value
104-
break
105-
}
106-
case key === 'aria-hidden': {
107-
attrs['aria-hidden'] = attrs['aria-label'] ? 'false' : val
108-
break
109-
}
110101
case key.startsWith('aria-'):
111102
case key.startsWith('data-'): {
112103
attrs[key.toLowerCase()] = val
@@ -119,13 +110,23 @@ export function convert(
119110
}
120111

121112
// Merge extraProps efficiently
122-
const { style: existingStyle, ...remaining } = extraProps
113+
const {
114+
style: existingStyle,
115+
'aria-label': ariaLabel,
116+
...remaining
117+
} = extraProps
123118

124119
if (existingStyle) {
125120
attrs.style = attrs.style
126121
? { ...attrs.style, ...existingStyle }
127122
: existingStyle
128123
}
129124

125+
// If an `aria-label` is set, ensure `aria-hidden` is false
126+
if (ariaLabel) {
127+
attrs['aria-label'] = ariaLabel
128+
attrs['aria-hidden'] = 'false'
129+
}
130+
130131
return createElement(element.tag, { ...remaining, ...attrs }, ...children)
131132
}

0 commit comments

Comments
 (0)