Keeps a chart in a frame from stranding the reader when they tab back out.
A chart in an iframe swallows every key it is sent: keyboard events do not
cross a frame boundary, so while the reader is inside the chart the page
around it hears nothing. That is right while they are reading — MAIDR binds
the arrows, Space, Backspace, Page Up and Page Down itself — which leaves
Shift + Tab as the way back to the page.
Usually the browser handles that on its own: Shift + Tab at the frame's first
tab stop moves to whatever precedes the frame in the host. But when nothing
usable precedes it, focus leaves the document altogether for the browser's
own UI, and the page cannot be driven from the keyboard until the reader tabs
all the way back in. A chart on a Quarto revealjs slide is exactly that
case: the deck's own controls are not rendered, so a chart is the first thing
on the page, and from inside it no key reaches the deck.
So this service watches for Shift + Tab at the frame's first tab stop, and
steps in only when the browser would strand the reader, handing focus to
the element that holds the frame — the slide, in a deck. Where the host has
somewhere real to go, the native tab order is left exactly as it was, and Tab
in the forward direction is never touched.
Nothing here can trap a reader: if the handoff cannot be completed, the
focused element is blurred so the next Shift + Tab does what the browser
would have done in the first place.
A chart that is not in a frame of its own meets the same dead end in one
place only: on a slide of a deck written into the page, where the chart is
the first thing on the page and the deck's keys are held off while the
chart has the focus (see HostGuardService). There the reader is handed to
the slide itself, and to nothing else: on any other page the elements
above the chart are its own wrappers or the page's, and the browser's own
Shift + Tab is the right answer.
Keeps a chart in a frame from stranding the reader when they tab back out.
A chart in an iframe swallows every key it is sent: keyboard events do not cross a frame boundary, so while the reader is inside the chart the page around it hears nothing. That is right while they are reading — MAIDR binds the arrows, Space, Backspace, Page Up and Page Down itself — which leaves Shift + Tab as the way back to the page.
Usually the browser handles that on its own: Shift + Tab at the frame's first tab stop moves to whatever precedes the frame in the host. But when nothing usable precedes it, focus leaves the document altogether for the browser's own UI, and the page cannot be driven from the keyboard until the reader tabs all the way back in. A chart on a Quarto
revealjsslide is exactly that case: the deck's own controls are not rendered, so a chart is the first thing on the page, and from inside it no key reaches the deck.So this service watches for Shift + Tab at the frame's first tab stop, and steps in only when the browser would strand the reader, handing focus to the element that holds the frame — the slide, in a deck. Where the host has somewhere real to go, the native tab order is left exactly as it was, and Tab in the forward direction is never touched.
Nothing here can trap a reader: if the handoff cannot be completed, the focused element is blurred so the next Shift + Tab does what the browser would have done in the first place.
A chart that is not in a frame of its own meets the same dead end in one place only: on a slide of a deck written into the page, where the chart is the first thing on the page and the deck's keys are held off while the chart has the focus (see
HostGuardService). There the reader is handed to the slide itself, and to nothing else: on any other page the elements above the chart are its own wrappers or the page's, and the browser's own Shift + Tab is the right answer.