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

fix (iOS): fix selectTextOnFocus in Fabric and non-Fabric by calling selectAll after becomeFirstResponder #44307

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,6 @@ - (void)textInputDidBeginEditing
self.backedTextInputView.attributedText = [NSAttributedString new];
}

if (_selectTextOnFocus) {
[self.backedTextInputView selectAll:nil];
}

[_eventDispatcher sendTextEventWithType:RCTTextEventTypeFocus
reactTag:self.reactTag
text:[self.backedTextInputView.attributedText.string copy]
Expand Down Expand Up @@ -611,6 +607,10 @@ - (UIView *)reactAccessibilityElement
- (void)reactFocus
{
[self.backedTextInputView reactFocus];

if (_selectTextOnFocus) {
[self.backedTextInputView selectAll:nil];
}
}

- (void)reactBlur
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,6 @@ - (void)textInputDidBeginEditing
[self textInputDidChange];
}

if (props.traits.selectTextOnFocus) {
[_backedTextInputView selectAll:nil];
[self textInputDidChangeSelection];
}

if (_eventEmitter) {
static_cast<const TextInputEventEmitter &>(*_eventEmitter).onFocus([self _textInputMetrics]);
}
Expand Down Expand Up @@ -425,6 +420,13 @@ - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args
- (void)focus
{
[_backedTextInputView becomeFirstResponder];

const auto &props = static_cast<const TextInputProps &>(*_props);

if (props.traits.selectTextOnFocus) {
[_backedTextInputView selectAll:nil];
[self textInputDidChangeSelection];
}
}

- (void)blur
Expand Down