Skip to content

Commit

Permalink
[fabric] Make text input resign first responder through the window in…
Browse files Browse the repository at this point in the history
…stance

Summary:
Fix AppKit exception throws when blurring text inputs by calling `resignFirstResponder` directly on the backing text input view.
Resigning the first responder state has to happen through the window by calling `[window makeFirstResponder:nil]` which will:
- call `resignFirstResponder` on the current first responder
- if successful, the window will become the first responder

Test Plan:
- Run Zeratul with Fabric
- Focus the search text input above the message threads
- Click inside the active message thread to trigger the auto-focus of the composer and the blur on the search field
- The focused field resigns the first responder status without throwing an exception

 https://pxl.cl/3GvZD

Reviewers: shawndempsey, #rn-desktop

Reviewed By: shawndempsey

Differential Revision: https://phabricator.intern.facebook.com/D50700782
  • Loading branch information
Nick Lefever authored and Saadnajmi committed Nov 20, 2024
1 parent 81527c1 commit edbec15
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,15 @@ - (void)focus

- (void)blur
{
#if !TARGET_OS_OSX // [macOS]
[_backedTextInputView resignFirstResponder];
#else // [macOS
NSWindow *window = _backedTextInputView.window;
if (window && window.firstResponder == _backedTextInputView) {
// Calling makeFirstResponder with nil will call resignFirstResponder and make the window the first responder
[window makeFirstResponder:nil];
}
#endif // macOS];
}

- (void)setTextAndSelection:(NSInteger)eventCount
Expand Down

0 comments on commit edbec15

Please sign in to comment.