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

Prevent spurious onBlur/onEndEditing events in <TextInput> elements with placeholder text #2160

Conversation

amgleitman
Copy link
Member

@amgleitman amgleitman commented Aug 12, 2024

Summary:

While working on #2159, I noticed that a single-line <TextInput> with a placeholder causes spurious onBlur and onEndEditing events. For some strange reason, setting placeholderAttributedString on macOS causes the NSTextDelegate to call textDidEndEditing. This PR blocks these events from reaching the JS side.

Test Plan:

Validated in RNTester that onBlur and onEndEditing don't get called unexpectedly when dealing with a <TextInput> with placeholder text.

@amgleitman amgleitman requested a review from a team as a code owner August 12, 2024 20:50
@Saadnajmi
Copy link
Collaborator

Since this is touching iOS code too, could we check if the problem reproes on iOS, and whether it can be usptreamed? If not, could we limit to macOS only blocks via ifdefs? I'm not sure we need to do that but it helps a little in merges.

@amgleitman
Copy link
Member Author

Since this is touching iOS code too, could we check if the problem reproes on iOS, and whether it can be usptreamed? If not, could we limit to macOS only blocks via ifdefs? I'm not sure we need to do that but it helps a little in merges.

This doesn't repro on iOS because editing attributedPlaceholder, the corresponding property in UIKit, doesn't call into the "end editing" delegate function. Nevertheless, it's not a bad idea to limit the scope of this change to macOS only.

@amgleitman amgleitman merged commit a44c574 into microsoft:main Aug 19, 2024
14 checks passed
@amgleitman amgleitman deleted the avoid-text-did-end-editing-from-editing-placeholder branch August 19, 2024 19:46
amgleitman added a commit to amgleitman/react-native-macos that referenced this pull request Aug 19, 2024
… with placeholder text (microsoft#2160)

* Add _isUpdatingPlaceholderText to prevent spurious "did end editing" notifications

* Organize macOS tags and ifdef blocks

---------

Co-authored-by: Adam Gleitman <[email protected]>
amgleitman added a commit to amgleitman/react-native-macos that referenced this pull request Aug 19, 2024
… with placeholder text (microsoft#2160)

* Add _isUpdatingPlaceholderText to prevent spurious "did end editing" notifications

* Organize macOS tags and ifdef blocks

---------

Co-authored-by: Adam Gleitman <[email protected]>
amgleitman added a commit that referenced this pull request Aug 19, 2024
)

* Deduplicate `textInputDid(Begin|End)Editing` calls for multiline `<TextInput>` elements (#2159)

* Add _isCurrentlyEditing to RCTBaseTextInputView

* Move _isCurrentlyEditing check earlier in textInputDidBeginEditing

* Adjust comment

* nit: remove extra newline

* Limit changes to macOS

---------

Co-authored-by: Adam Gleitman <[email protected]>

* Prevent spurious onBlur/onEndEditing events in `<TextInput>` elements with placeholder text (#2160)

* Add _isUpdatingPlaceholderText to prevent spurious "did end editing" notifications

* Organize macOS tags and ifdef blocks

---------

Co-authored-by: Adam Gleitman <[email protected]>

---------

Co-authored-by: Adam Gleitman <[email protected]>
amgleitman added a commit that referenced this pull request Aug 19, 2024
)

* Deduplicate `textInputDid(Begin|End)Editing` calls for multiline `<TextInput>` elements (#2159)

* Add _isCurrentlyEditing to RCTBaseTextInputView

* Move _isCurrentlyEditing check earlier in textInputDidBeginEditing

* Adjust comment

* nit: remove extra newline

* Limit changes to macOS

---------

Co-authored-by: Adam Gleitman <[email protected]>

* Prevent spurious onBlur/onEndEditing events in `<TextInput>` elements with placeholder text (#2160)

* Add _isUpdatingPlaceholderText to prevent spurious "did end editing" notifications

* Organize macOS tags and ifdef blocks

---------

Co-authored-by: Adam Gleitman <[email protected]>

---------

Co-authored-by: Adam Gleitman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants