diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm index dbee656c95e6..c3f4630ff666 100644 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm @@ -201,7 +201,13 @@ - (void)setTextContainerInset:(UIEdgeInsets)textContainerInset [self setNeedsLayout]; #else // [macOS ((RCTUITextFieldCell*)self.cell).textContainerInset = _textContainerInset; + [self _relocateFieldEditor]; +#endif // macOS] +} +#if TARGET_OS_OSX // [macOS +- (void)_relocateFieldEditor +{ if (self.currentEditor) { NSRange selectedRange = self.currentEditor.selectedRange; @@ -213,9 +219,20 @@ - (void)setTextContainerInset:(UIEdgeInsets)textContainerInset start:selectedRange.location length:selectedRange.length]; } -#endif // macOS] } +- (void)setFrameSize:(NSSize)newSize +{ + BOOL sizeChanged = !NSEqualSizes(newSize, self.frame.size); + [super setFrameSize:newSize]; + // NSTextField resizes the field editor of a field being edited to the cell's drawing rect, which + // leaves out the title rect's padding and vertical centering, so the text jumped to the top. + if (sizeChanged) { + [self _relocateFieldEditor]; + } +} +#endif // macOS] + #if TARGET_OS_OSX // [macOS - (NSResponder *)responder