liveBook · Manning

Tabindex

As explained in D3.js in Action, Third Edition

The tabindex attribute controls whether an HTML or SVG element can receive keyboard focus and its position in sequential focus navigation.

The tabindex attribute makes SVG elements reachable with the Tab key and assigns their order in sequential keyboard navigation. Its integer value controls focus order; sorting data before creating circles also determines their DOM and focus order. section 10.2.4

Use tabindex when interactive visualization elements must work without a mouse:

  • Sort cetacean data before binding it to scatterplot circles, then assign tabindex="0". section 10.2.4
  • Pair the mouseenter and mouseleave tooltip handlers with focus and blur handlers. section 10.2.4
  • Repeat the attributes and handlers when filters create new DOM elements. 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);

Inspect the combined tabindex, focus, blur, and pointer-event implementation for accessible scatterplot tooltips. section 10.2.4

Keyboard-accessible scatterplot

A cetacean scatterplot adds instructions telling users to pass over circles or access them with the Tab key. Focus reveals the same tooltip as mouse entry, while blur hides it. section 10.2.4

How D3.js in Action, Third Edition covers it

How deep it goes
Defines integer-based focus order and demonstrates dynamic SVG updates, focus, blur, sorting, and repeated bindings.
Examples
Uses a filtered cetacean scatterplot whose circles reveal tooltips through pointer entry or keyboard focus.
What it assumes
Assumes familiarity with SVG elements, data binding, DOM creation, and event listeners.
What you can do after
Apply tabindex, focus, and blur handlers to make dynamic SVG visualization interactions keyboard-accessible.
How it connects
Connects SVG, DOM order, keyboard navigation, focus events, blur events, data binding, and tooltips.

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.