FormidableLabs / eslint-plugin-react-native-a11y

React Native specific accessibility linting rules.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error message for `-descriptors` rule is out of sync with accessibility-hint rule setting

AlanSl opened this issue · comments

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.