liveBook · Manning

Blur event

As explained in D3.js in Action, Third Edition

A blur event is a browser event dispatched when an element loses input focus.

A blur event fires when an element loses input focus. Pair it with focus to make interactive visualization elements respond to keyboard navigation: reveal a tooltip when a circle receives focus, then hide it when focus moves away. section 10.2.4

innerChart
  .selectAll(".cetacean")
  .data(data.sort((a, b) => a.global_population_estimate - 
    b.global_population_estimate))
  .join("circle")
    .attr("class", d => `cetacean cetacean-${d.status}`)
    ...
    .attr("tabindex", 0)
    .on("mouseenter focus", showTooltip)
    .on("mouseleave blur", hideTooltip);

Attach focus and blur alongside mouse events so the same tooltip works for keyboard and pointer users. section 10.2.4

Use the event as part of an accessible interaction pattern:

  • Give SVG shapes a tabindex value so keyboard users can focus them. section 10.2.4
  • Combine mouseenter with focus to show the tooltip, and mouseleave with blur to hide it. section 10.2.4
  • Reapply the tabindex and listeners when filtering creates new DOM elements. section 10.2.4

How D3.js in Action, Third Edition covers it

How deep it goes
Explains the event’s definition and its listener pairing, then applies it to entering visualization elements without browser internals.
Examples
Uses keyboard-accessible cetacean scatterplot circles whose tooltips hide on blur.
What you can do after
Apply it via the on() method to hide visualization tooltips when keyboard focus leaves an element.
How it connects
Connects blur event with focus event, tabindex, keyboard navigation, tooltips, and data joins.

Also explained in

Compare how 2 books explain blur event →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of D3.js in Action, Third Edition. The section links point to the parts of the book it draws on.