Should onFocus/onBlur bubble or not?
See original GitHub issueI’m confused about whether onFocus/onBlur events should bubble in preact, like they do in React.
In this example using preact 10.0.0-beta.1 they don’t bubble https://codesandbox.io/embed/5wxk9zk7lx
…whereas in the Preact repl they do bubble https://preactjs.com/repl
export default () =>(
<div onFocus={() => console.log("FOCUS")}>
<div>
Focus this input
<br />
<input />
</div>
</div>
);
So which example is correct Preact behavior?
If they should not bubble, then that fact really should be covered on the Differences to React page
… or even receive its own page about events and how onChange
is different and how only some DOM event prop names may be camelCased (onClick
), while others must be lowercased (like: onfocusin
)
Then also the REPL should be fixed to behave like “normal” Preact.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:13 (7 by maintainers)
Top Results From Across the Web
onfocus vs onfocusin & onblur vs onfocusout - Stack Overflow
The main difference is that the onfocus event does not bubble. Therefore, if you want to find out whether an element or its...
Read more >Focusing: focus/blur - The Modern JavaScript Tutorial
They do not bubble. Can use capturing state instead or focusin/focusout . Most elements do not support focus by default. Use tabindex to...
Read more >Element: blur event - Web APIs | MDN
The blur event fires when an element has lost focus. The event does not bubble, but the related focusout event that follows does...
Read more >blur and focus - Events - QuirksMode
The reason focus and blur don't bubble is that the events mean something quite different on the window and on any other focusable...
Read more >JavaScript: Focus and Blur events DON'T bubble! #shorts
JavaScript focus and blur events tutorial. HTML DOM events.#javascript #dom #webdevelopersDownload my FREE "Google Search Secrets for ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think this behaviour got introduced by accident as a side effect of supporting
on**Capture
events.FWIW a compat fix would be to transform
props.onFocus
toprops.onFocusCapture
.Given that there are native
focusin
andfocusout
events which do bubble, I think the behaviour in keeping with the “closer to the metal” philosophy would be to avoid special-casing this event and require use ofonFocusIn
oronFocusOut
props if users want bubbling.A counter-argument is React compatibility if there are important third-party components which rely on the behaviour of
onFocus
. Potentially that could be addressed in thepreact/compat
package though.