In short - the has-valid-accessibility-descriptors's rule's error message is static text that doesn't take into account the config's settings on whether accessibilityHint is actually required with accessibilityLabel.
We have eslint-plugin-react-native-a11y set up with has-accessibility-hint rule disabled on a library of components intended to be shared between web and native projects, because accessibilityHint isn't supported in React Native Web, so mandating its use risks misleading devs into thinking an element has full contextual info when actually the hint part is unavailable on Web. Instead, we advise devs to use complete labels that contain full contextual info across platforms.
We recently updated to 3.x and were surprised to see an error seemingly complaining about missing hints with labels:
Missing a11y props. Expected one of: accessibilityRole OR BOTH accessibilityLabel + accessibilityHint OR BOTH accessibilityActions + onAccessibilityAction
...however, it turns out that the rule was correctly following our settings: if the element in question was given an accessibilityLabel without an accessibilityHint, there was no error as per our disabling of the accessibilityHint rule, but if the accessibilityLabel prop was removed, then the error misleadingly implied an accessibilityHint was also needed.
So the behaviour is fine, but the error message didn't reflect the behaviour of the rule.
Proposed fix
Replace the BOTH accessibilityLabel + accessibilityHint part of the error message here
|
'Missing a11y props. Expected one of: accessibilityRole OR BOTH accessibilityLabel + accessibilityHint OR BOTH accessibilityActions + onAccessibilityAction'; |
with just
accessibilityLabel if the appropriate accessiblityHint rule is not active.
In short - the
has-valid-accessibility-descriptors's rule's error message is static text that doesn't take into account the config's settings on whetheraccessibilityHintis actually required withaccessibilityLabel.We have eslint-plugin-react-native-a11y set up with
has-accessibility-hintrule disabled on a library of components intended to be shared between web and native projects, becauseaccessibilityHintisn't supported in React Native Web, so mandating its use risks misleading devs into thinking an element has full contextual info when actually the hint part is unavailable on Web. Instead, we advise devs to use complete labels that contain full contextual info across platforms.We recently updated to
3.xand were surprised to see an error seemingly complaining about missing hints with labels:...however, it turns out that the rule was correctly following our settings: if the element in question was given an
accessibilityLabelwithout anaccessibilityHint, there was no error as per our disabling of the accessibilityHint rule, but if theaccessibilityLabelprop was removed, then the error misleadingly implied anaccessibilityHintwas also needed.So the behaviour is fine, but the error message didn't reflect the behaviour of the rule.
Proposed fix
Replace the
BOTH accessibilityLabel + accessibilityHintpart of the error message hereeslint-plugin-react-native-a11y/src/rules/has-valid-accessibility-descriptors.js
Line 18 in e5b0f97
accessibilityLabelif the appropriate accessiblityHint rule is not active.