Skip to content

Commit

Permalink
Fixed accesibility problem with <TextInput>'s Clear Button
Browse files Browse the repository at this point in the history
Summary:
UITextView is accessible by default (some nested views are) and disabling that is not supported.

The problem happened because JS side sets `isAccessible` flag for UITextView and UITextField to `true` (with good intent!), which actually disables (surprise!) bult-in accessibility of TextInput on iOS.
On iOS accessible elements cannot be nested, so enabling accessibily for some container view (even in a case where this is view is a public API of TextInput on iOS) shadows some features implemented inside the component.

(Disabling accessibility of TextInput via `accessible=false` was never supported.)

Reviewed By: JoshuaGross

Differential Revision: D15280667

fbshipit-source-id: 72509b40383db6ef66c4263bd920f5ee56a42fc1
  • Loading branch information
shergin authored and facebook-github-bot committed May 9, 2019
1 parent 078f14c commit 4e37d37
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Libraries/Text/TextInput/Multiline/RCTUITextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ - (void)dealloc
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark - Accessibility

- (void)setIsAccessibilityElement:(BOOL)isAccessibilityElement
{
// UITextView is accessible by default (some nested views are) and disabling that is not supported.
// On iOS accessible elements cannot be nested, therefore enabling accessibility for some container view
// (even in a case where this view is a part of public API of TextInput on iOS) shadows some features implemented inside the component.
}

- (NSString *)accessibilityLabel
{
NSMutableString *accessibilityLabel = [NSMutableString new];
Expand Down
9 changes: 9 additions & 0 deletions Libraries/Text/TextInput/Singleline/RCTUITextField.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ - (void)_textDidChange
_textWasPasted = NO;
}

#pragma mark - Accessibility

- (void)setIsAccessibilityElement:(BOOL)isAccessibilityElement
{
// UITextField is accessible by default (some nested views are) and disabling that is not supported.
// On iOS accessible elements cannot be nested, therefore enabling accessibility for some container view
// (even in a case where this view is a part of public API of TextInput on iOS) shadows some features implemented inside the component.
}

#pragma mark - Properties

- (void)setTextContainerInset:(UIEdgeInsets)textContainerInset
Expand Down

1 comment on commit 4e37d37

@ericlewis
Copy link
Contributor

Choose a reason for hiding this comment

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

ha! that is awesome!

Please sign in to comment.