DEV Community

Andreas Sander
Andreas Sander

Posted on • Originally published at andi1984.dev

1

React - Synthetic blur event

First, let's have a look at what the blur event actually is.

Definition

The blur event fires when an element has lost focus. The main difference between this event and focusout is that focusout bubbles while blur does not.

-- MDN

Native browser behaviour

It is clearly saying that the blur event does not bubble up the DOM tree to all parent elements. I proved this by a CodePen demo.

Behaviour within React

But today I found out together with my colleagues that within React the synthetic blur event is bubbling to the container component in the sense that onBlur on a parent component is getting triggered by it as you can see within a CodeSandbox demo here.

React will bubble these events through its event model. So we can listen for focus and blur events at the root of a component and react to these events fired on its child nodes.

-- J. Renée Beach

So on the one hand this makes kind of sense within the React ecosystem, on the other hand not knowing that and following the native specs – which we all should follow – it can be quite confusing.

Summary

In the end, React is breaking out of the standard, the specification – and it's not the only issue with synthetic events. They are probably doing so for us, developers. It helps to mentally stay within their ecosystem, their logical rules which are also having advantages, but it is a risky discrepancy between React and the W3C standards.

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more