liveBook · Manning

Focusable element

As explained in D3.js in Action, Third Edition

A focusable SVG element is an SVG element that can receive keyboard focus in a document.

A focusable SVG element can receive keyboard focus in a document. Set tabindex="0" on chart marks so users can reach them with the Tab key. section 10.2.4

Sort data before creating the marks to control their DOM and focus order. Pair mouse tooltip handlers with focus and blur handlers so keyboard users receive the same feedback. section 10.2.4

const updatedData = datum.id === "all"
  ? data
  : data.filter(d => d.hemisphere === datum.id)
        .sort((a, b) => a.global_population_estimate - 
          b.global_population_estimate);

innerChart
  .selectAll("circle")
  .data(updatedData, d => d.uid)
  .join(
    enter => enter
      .append("circle")
      ...
      .attr("tabindex", 0)
      .on("mouseenter focus", showTooltip)
      .on("mouseleave blur", hideTooltip)
      ...

Reapply tabindex and focus/blur handlers inside the data join whenever filtering creates new SVG circles. section 10.2.4

How D3.js in Action, Third Edition covers it

How deep it goes
Explains tabindex values, DOM focus order, focus and blur events, and reapplication after data joins.
Examples
Uses sorted cetacean scatterplot circles, filtered chart updates, and tooltips revealed by mouseenter or focus.
What it assumes
Assumes mouse-based tooltip interactions and data binding, while teaching how to expose the same interaction through the keyboard.
What you can do after
Apply it via SVG attributes and event listeners to make scatterplot tooltips keyboard-accessible.
How it connects
Connects SVG elements with tabindex, DOM order, keyboard navigation, focus events, blur events, tooltips, and data joins.

Also explained in

Compare how 2 books explain focusable element →

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.