Skip to content

iOS/Android: Text input error for screenreaders #30848

Closed
@amarlette

Description

Requires API Proposal

This issue requires a new API. An API proposal should be added and discussed before proceeding with implementation. The API proposal can be added in the comments of this issue or linked as a separate issue.

Description

Cannot specify error text on TextInputs. Errors for form fields, while they can be displayed visually in many unique ways, need to have a strong association with the problematic field itself for accessibility. Otherwise, any users who can't visually see the relation of the error to the field won't necessarily know which field is the problem.

React Native version:

v0.63

Expected Results

Upon focus of a text input in an error state, the error message specified should announced after the main focus announcement, prefixed with "Error: ". Upon changing the contents of a text input which puts the input into an error state, an error message should be announced prefixed with "Error: ".

Snack

https://snack.expo.io/X4NIqnJ2K

Android Details

To implement error states on Android, you should call the setError method of the TextView. This will automatically set the correct properties on the AccessibilityNodeInfo that will inform screen readers to this state. If you need to do this manually, what this does behind the scenes is call setContentInvalid(true) and setError(youErrorString) on the AccessibilityNodeInfo.

iOS Details

iOS has no standard pattern for the presentation of error states on text inputs, so I'd recommend we follow Android's pattern here. To do this, you'll need to implement a key press listener, and on change, detect if the field is now in an error state. If it is, you'll need to make a manual screen reader announcement of the error message, and append this message to the accessibilityValue for the field.

Metadata

Assignees

No one assigned

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions