Skip to content

Conversation

@ctrlaltdylan
Copy link
Contributor

Including more substantial documentation around the onFocus and onBlur events that aren't so common sense on first look.

Including more substantial documentation around the `onFocus` and `onBlur` events that aren't so common sense on first look.
@facebook-github-bot
Copy link
Collaborator

Hi @ctrlaltdylan!

Thank you for your pull request and welcome to our community.We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file.

In order for us to review and merge your code, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot
Copy link
Collaborator

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

Co-authored-by: Darsh Shah <imdarshshah@gmail.com>
@gaearon
Copy link
Member

gaearon commented Sep 25, 2020

How do you feel about incorporating this example? Seems like it’s a useful collection of behaviors people want. facebook/react#6410 (comment)

@reactjs-bot
Copy link

reactjs-bot commented Sep 25, 2020

Deploy preview for reactjs ready!

Built with commit 3674276

https://deploy-preview-3044--reactjs.netlify.app


#### onFocus

The `onFocus` prop is initiated when focus is on the element. For example, when the user clicks on a text input element, the function defined with the `onFocus` prop is called.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is certainly true for chrome on windows and linux as far as I know. But does not apply to e.g. firefox macOS.

More specifically: By spec it is up to the user agent (e.g. a browser) to determine whether a clicked element is also focused.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or it might be true for inputs. I was a bit suspicious because of the "click-focus" association which is a bit tricky on other platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eps1lon I just booted up Firefox + Mac and ran through a sample:

https://www.loom.com/share/34f1a18300b44187b7a65e2c01b73f8b

Sandbox: https://codesandbox.io/s/busy-browser-0me16?file=/src/App.js:146-191

It appears to be 1:1 to Chrome, at least for the basic examples I wanted to document. If you find something else different please feel free to edit/tack on.

Adding an example of `relatedTarget` to determine orgin of onblur or onfocus events
@ctrlaltdylan
Copy link
Contributor Author

How do you feel about incorporating this example? Seems like it’s a useful collection of behaviors people want. facebook/react#6410 (comment)

@gaearon Forked your explanation and changed the logging events to be a tad more people friendly and specific. Added a few more examples to cover vanilla onFocus and onBlur on a solo element.

Fixing `onBlur` example bug.

Co-authored-by: Darsh Shah <imdarshshah@gmail.com>
Copy link
Contributor

@iamdarshshah iamdarshshah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

@gaearon
Copy link
Member

gaearon commented Sep 25, 2020

Code blocks need to be consistently indented and should use JS language

Fixing spacing in `onBlur` `onFocus` examples and tagging them with `javascript`
@ctrlaltdylan
Copy link
Contributor Author

@gaearon thanks, missed that. Updated onBlur and onFocus examples with the javascript tag and fixed spacing so it matches the other examples.

@vercel
Copy link

vercel bot commented Oct 23, 2020

Deployment failed with the following error:

The most recent charge for your active payment method has failed. Please update it here: https://vercel.com/teams/fbopensource/settings/billing

@gaearon gaearon merged commit 4a62c0a into reactjs:master Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants