liveBook · Manning

Event bubbling

As explained in React Quickly, Second Edition

Event bubbling is the propagation stage in which an event travels from its originating target toward outer targets.

Event bubbling is the propagation stage in which an event travels from its originating target toward outer targets. React event handlers use JSX properties such as onClick, and React makes all events bubble, including focus and blur. section 8.10 section 8.3.4

Use bubbling deliberately when handling nested interface elements:

  • Let an outer handler respond when an inner element is activated. section 8.3.4
  • Call evt.stopPropagation() when an inner interaction must not reach an outer listener. section 8.8.3
  • Use evt.preventDefault() for unwanted browser actions, such as a form submission reload; it does not stop propagation. section 8.10

Closing a menu only from outside

An expandable menu can listen for pointerdown on window to close itself, then stop pointerdown events on the menu so clicks inside do not bubble to window. A useRef reference connects the React component to the menu DOM node, while effect cleanup removes both listeners. section 8.8.3

<label onFocusCapture={handler1} onFocus={handler3}>
 <input onFocus={handler2} />
</label>

Trace focus from the input through the capture handler, target handler, and bubbling handler on the label. section 8.3.4

How React Quickly, Second Edition covers it

How deep it goes
Explains propagation order, React’s focus and blur behavior, stopping propagation, and listener cleanup through a menu implementation.
Examples
Demonstrates nested focus handlers and an expandable menu that distinguishes inside clicks from outside pointer events.
What it assumes
Assumes basic JSX and HTML elements while teaching how user interactions become events handled by React.
What you can do after
Apply it via React handlers and DOM listeners to control nested interactions and prevent selected events reaching outer targets.
How it connects
Links event bubbling with event capturing, DOM events, event listeners, preventDefault, stopPropagation, and useRef.

Also explained in

Compare how 3 books explain event bubbling →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of React Quickly, Second Edition. The section links point to the parts of the book it draws on.