Agent Wranglers

AXS-73Optional

Keep the focused element fully in view

Keep every part of the focused element in view, not only some of it. This is WCAG 2.2 criterion 2.4.12 (AAA), a step past the legal AA bar in Never hide the focused element.

How to do it

People who use a screen magnifier or a keyboard lose track of a control that is half under a sticky bar. Give scroll-padding the full height of every fixed bar, top and bottom, plus a margin. Never let a cookie banner or chat button float over content without reserving that space.

Examples

JavaScript example

const points = await page.evaluate(() => {
  const box = document.activeElement.getBoundingClientRect();
  const spots = [[box.left + 1, box.top + 1], [box.right - 1, box.top + 1], [box.left + 1, box.bottom - 1], [box.right - 1, box.bottom - 1], [box.x + box.width / 2, box.y + box.height / 2]];
  return spots.map(([x, y]) => document.activeElement.contains(document.elementFromPoint(x, y)));
});
expect(points.every(Boolean)).toBe(true);

Python example

points = page.evaluate("""() => {
  const box = document.activeElement.getBoundingClientRect();
  const spots = [[box.left + 1, box.top + 1], [box.right - 1, box.top + 1], [box.left + 1, box.bottom - 1], [box.right - 1, box.bottom - 1], [box.x + box.width / 2, box.y + box.height / 2]];
  return spots.map(([x, y]) => document.activeElement.contains(document.elementFromPoint(x, y)));
}""")
assert all(points)

How to check

A browser test tabs through each long page. document.elementFromPoint at the centre and at all four corners of every focused element returns the element or something inside it.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/accessibility/keyboard-and-focus/focus-fully-visible">Agent Wranglers accessibility playbook</a>. In code you write, add a comment next to it with the same link.