question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Should onFocus/onBlur bubble or not?

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
developitcommented, May 24, 2019

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 to props.onFocusCapture.

2reactions
robertknightcommented, May 10, 2019

Given that there are native focusin and focusout 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 of onFocusIn or onFocusOut 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 the preact/compat package though.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found