From 95242de55f9482b79a12f754d228da72b3e9efbe Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Mon, 3 Aug 2026 18:45:12 -0700 Subject: [PATCH 1/2] fix(macos): vertically center single-line TextInput content Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 56169cae-e214-4ad0-8e16-69e3af7a5948 --- .../Libraries/Text/TextInput/Singleline/RCTUITextField.mm | 8 +++++++- .../TextInput/Singleline/macOS/RCTUISecureTextField.mm | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm index 0f988c19d5c2..d9405ee9ef9b 100644 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm @@ -33,7 +33,13 @@ @implementation RCTUITextFieldCell - (NSRect)titleRectForBounds:(NSRect)rect { - return UIEdgeInsetsInsetRect([super titleRectForBounds:rect], self.textContainerInset); + NSRect titleRect = UIEdgeInsetsInsetRect([super titleRectForBounds:rect], self.textContainerInset); + CGFloat contentHeight = self.cellSize.height; + if (contentHeight < titleRect.size.height) { + titleRect.origin.y += (titleRect.size.height - contentHeight) / 2; + titleRect.size.height = contentHeight; + } + return titleRect; } - (void)editWithFrame:(NSRect)rect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)delegate event:(NSEvent *)event diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.mm b/packages/react-native/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.mm index 6f332dc1701c..386a8114d2c3 100644 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.mm +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.mm @@ -30,7 +30,13 @@ @implementation RCTUISecureTextFieldCell - (NSRect)titleRectForBounds:(NSRect)rect { - return UIEdgeInsetsInsetRect([super titleRectForBounds:rect], self.textContainerInset); + NSRect titleRect = UIEdgeInsetsInsetRect([super titleRectForBounds:rect], self.textContainerInset); + CGFloat contentHeight = self.cellSize.height; + if (contentHeight < titleRect.size.height) { + titleRect.origin.y += (titleRect.size.height - contentHeight) / 2; + titleRect.size.height = contentHeight; + } + return titleRect; } - (void)editWithFrame:(NSRect)rect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)delegate event:(NSEvent *)event From 522769e4503a4ece7302282f7386b501fc6355c3 Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Mon, 3 Aug 2026 19:05:46 -0700 Subject: [PATCH 2/2] docs(macos): explain TextInput vertical centering Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 56169cae-e214-4ad0-8e16-69e3af7a5948 --- .../Libraries/Text/TextInput/Singleline/RCTUITextField.mm | 1 + .../Text/TextInput/Singleline/macOS/RCTUISecureTextField.mm | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm index d9405ee9ef9b..dbee656c95e6 100644 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm @@ -34,6 +34,7 @@ @implementation RCTUITextFieldCell - (NSRect)titleRectForBounds:(NSRect)rect { NSRect titleRect = UIEdgeInsetsInsetRect([super titleRectForBounds:rect], self.textContainerInset); + // Center the intrinsic text height within the padded control bounds. CGFloat contentHeight = self.cellSize.height; if (contentHeight < titleRect.size.height) { titleRect.origin.y += (titleRect.size.height - contentHeight) / 2; diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.mm b/packages/react-native/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.mm index 386a8114d2c3..c5aeaf80ac62 100644 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.mm +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.mm @@ -31,6 +31,7 @@ @implementation RCTUISecureTextFieldCell - (NSRect)titleRectForBounds:(NSRect)rect { NSRect titleRect = UIEdgeInsetsInsetRect([super titleRectForBounds:rect], self.textContainerInset); + // Center the intrinsic text height within the padded control bounds. CGFloat contentHeight = self.cellSize.height; if (contentHeight < titleRect.size.height) { titleRect.origin.y += (titleRect.size.height - contentHeight) / 2;