Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make TextInput "clear text" button accessible #17230

Closed
wants to merge 1 commit into from

Conversation

haitaoli
Copy link
Contributor

@haitaoli haitaoli commented Dec 15, 2017

Motivation

This PR makes TextInput "clear text" button accessible. UITextField is wrapped inside a RCTUITextField control which has isAccessibleElement set to TRUE. This prevents iOS accessibility interface from enumerating child elements. This change makes the RCTextField not accessible, but allows child elements to be enumerated if the accessible prop is set to true.

Issue

#16989

Test Plan

Manually tested with RNTester sample app and accessibility explorer.

Release Notes

[IOS] [BUGFIX] [TextInput] - Made "clear text" button accessible

@haitaoli haitaoli requested a review from shergin as a code owner December 15, 2017 21:33
@pull-bot
Copy link

pull-bot commented Dec 15, 2017

Attention: @shergin

Generated by 🚫 dangerJS

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 15, 2017
@shergin
Copy link
Contributor

shergin commented Dec 18, 2017

How does this affect the accessibility of UITextView's content?

@haitaoli
Copy link
Contributor Author

The UITextView is exposed to accessibility interface as a child element. accessibilityLabel and accessibilityValue are not affected on TextInput in my tests.

@shergin
Copy link
Contributor

shergin commented Dec 18, 2017

@haitaoli Ooops, I meant UITextField.
So, I actually I have two Q:

  • Should we apply same changes for RCTUITextView? Why?
  • Have you tested this? Does it work exactly like it worked especially for text content?

@shergin
Copy link
Contributor

shergin commented Dec 18, 2017

Thank you for tackling this, BTW! This is really valuable!

@haitaoli
Copy link
Contributor Author

Is UITextView used when TextInput is multi-line? UITextView doesn't have a clear button so it doesn't need this fix. Here are the screenshots of accessibility explorer output on the TextInput component and it's "clear text" button:

screen shot 2017-12-18 at 3 37 38 pm
screen shot 2017-12-18 at 3 37 50 pm

@haitaoli
Copy link
Contributor Author

haitaoli commented Dec 18, 2017

accessibilityLabel on TextInput shows up in accessibility explorer correctly with this PR.

@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label Dec 19, 2017
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shergin is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot added Import Failed and removed Import Started This pull request has been imported. This does not imply the PR has been approved. labels Dec 19, 2017
@facebook-github-bot
Copy link
Contributor

I tried to merge this pull request into the Facebook internal repo but some checks failed. To unblock yourself please check the following: Does this pull request pass all open source tests on GitHub? If not please fix those. Does the code still apply cleanly on top of GitHub master? If not can please rebase. In all other cases this means some internal test failed, for example a part of a fb app won't work with this pull request. I've added the Import Failed label to this pull request so it is easy for someone at fb to find the pull request and check what failed. If you don't see anyone comment in a few days feel free to comment mentioning one of the core contributors to the project so they get a notification.

@haitaoli haitaoli force-pushed the master branch 2 times, most recently from addfdbc to df5acce Compare January 27, 2018 06:42
@shergin
Copy link
Contributor

shergin commented Jan 29, 2018

@haitaoli Well, actually RCTUITextField does not wrap it, it subclasses UITextField. So, the text input should behave very well in terms of accessibility. And I am afraid that this changes can interfere with built-in logic. 🤔

Why do you/we need to make "clear" button accessible in the first place?

@haitaoli
Copy link
Contributor Author

@shergin On iOS, an element can either be accessible, or contain accessible children, but not both: https://developer.apple.com/documentation/uikit/accessibility/uiaccessibilitycontainer. If the TextInput has a button, then we want it accessible, because it's a button and people with disabilities will find it useful. In React Native, the accessible prop is applied the to view directly by default so it cannot contain accessible children elements. The UITextView internally contains a text box implementation. But returning the child elements, accessibility tools such as Voice Over can see both text box and clear button.

@shergin
Copy link
Contributor

shergin commented Jan 29, 2018

@haitaoli So, how does the current default behaviour of different from default UITextView/UITextField? If it's not, we have to be really really careful because this component is really really important and must be perfect from an accessibility perspective. And it must be not RN specific issue, so we have to try to find how other products address it.

I am not an accessible expert, so I don't know for sure, but... do you people with disabilities really need this button? Maybe there is a special gesture for cleaning the text input so they simply don't need a button?

@haitaoli
Copy link
Contributor Author

@shergin the current behavior of RCTUITextField overrides isAccessibilityElement (via one of the base classes) to return a value based on accessible prop, which disables enumerating child elements. This is the correct behavior for most elements that don't have accessible child elements. But TextInput is different. This is RN specific. I believe this button is important. Without it the user can only use the "backspace" key, and it takes 2 taps to remove one character. Imagine doing this while you cannot see the screen.

@shergin
Copy link
Contributor

shergin commented Feb 4, 2018

Yes, I tested on a real device and in standard apps clear button is accessible. So, if in RN it does not by default, we have to fix it. But first of all, we have to understand why it is happening now.
@haitaoli DId you tried to override setIsAccessibilityElement method and test which component calls it?

@haitaoli
Copy link
Contributor Author

haitaoli commented Feb 5, 2018

I didn't. But it should be called on any component with accessible prop set to true.

@react-native-bot react-native-bot added Ran Commands One of our bots successfully processed a command. Component: TextInput Related to the TextInput component. Bug Fix 🐛 Platform: iOS iOS applications. labels Mar 16, 2018
@janicduplessis
Copy link
Contributor

janicduplessis commented Oct 13, 2018

Seems like it is marked accessible because of the native TextInput component is wrapped with TouchableWithoutFeedback

<TouchableWithoutFeedback
onLayout={props.onLayout}
onPress={this._onPress}
rejectResponderTermination={true}
accessible={props.accessible}
accessibilityLabel={props.accessibilityLabel}
accessibilityTraits={props.accessibilityTraits}
nativeID={this.props.nativeID}
testID={props.testID}>
{textContainer}
</TouchableWithoutFeedback>

which is accessible by default

accessible: this.props.accessible !== false,

Maybe this could just be fixed in js land?

cc @shergin

@haitaoli
Copy link
Contributor Author

I don't think there is a workaround on JS side. The native view cannot be set to be accessible without hiding that clear button.

@cpojer
Copy link
Contributor

cpojer commented Jan 28, 2019

Seems like this is an RN in open source issue, and @janicduplessis is right that we can probably fix this with a JS only fix. I'm gonna close this PR for now but happy to reopen if I'm wrong.

@cpojer cpojer closed this Jan 28, 2019
@hramos hramos added Merged This PR has been merged. and removed Import Failed labels Mar 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Component: TextInput Related to the TextInput component. Merged This PR has been merged. Platform: iOS iOS applications. Ran Commands One of our bots successfully processed a command.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants