This PR fixes usage of the ariaLabel prop, which previously provided labels that were hidden behind a parent element with the aria-hidden attribute, and were inaccessible to screenreaders as a result.
I removed the hidden span in favour of using an actual aria-label attribute on the parent element, and toggling the presence of the aria-hidden attribute based on the presence of the ariaLabel prop. As screen readers should announce an element’s aria-label instead of its text content, it should be safe to remove the aria-hidden attribute here.
I preserved the existing behaviour of adding the aria-hidden attr on the parent element where possible (ie. in the absence of an ariaLabel prop), since it seems like a sensible default. It provides a baseline level of improved accessibility, and is otherwise an attribute that many developers are likely to overlook (and when they don’t, they are likely to set it to true, anyway) — but I'm not opposed to also making this configurable via a prop, as well.
Changes
Remove inaccessible hidden span in favour of aria-label attribute usage.
Remove now-unused screenreader-related styles.
Update tests to check for presence of aria-label attribute, instead of nested span.
Makes a couple minor formatting changes in the JSDoc block, for consistency.
Related Issue
61 — AriaLabel Prop is Effectively Broken
Overview
This PR fixes usage of the
ariaLabel
prop, which previously provided labels that were hidden behind a parent element with thearia-hidden
attribute, and were inaccessible to screenreaders as a result.I removed the hidden span in favour of using an actual
aria-label
attribute on the parent element, and toggling the presence of thearia-hidden
attribute based on the presence of theariaLabel
prop. As screen readers should announce an element’saria-label
instead of its text content, it should be safe to remove thearia-hidden
attribute here.I preserved the existing behaviour of adding the
aria-hidden
attr on the parent element where possible (ie. in the absence of anariaLabel
prop), since it seems like a sensible default. It provides a baseline level of improved accessibility, and is otherwise an attribute that many developers are likely to overlook (and when they don’t, they are likely to set it to true, anyway) — but I'm not opposed to also making this configurable via a prop, as well.Changes
aria-label
attribute usage.aria-label
attribute, instead of nested span.