Rule

Popover and command targets

popovertarget and commandfor must point at an element they can act on.

Rule
invoker-target
WCAG 2.2
4.1.2 Name, Role, Value (opens in a new tab) (Level A)
Severity
Serious

What it checks

HTML lets a button open and close a popover or a dialog without script: popovertarget names the popover, and commandfor with a command names the element to act on. The browser then tells assistive technology whether the target is open and which element the button controls. The rule fails an enabled button whose reference cannot work: an id that names no element, a popovertarget aimed at an element with no popover attribute, a commandfor with no command, or a dialog command such as show-modal aimed at something that is not a <dialog>. Pressing such a button does nothing, and the state the browser would expose is missing.

Command names the rule does not recognise, including custom ones a page handles itself, are not judged.

Example

Fails

<button popovertarget="filters">Filters</button>
<div id="filters">
  <label><input type="checkbox"> In stock</label>
</div>

Passes

<button popovertarget="filters">Filters</button>
<div id="filters" popover>
  <label><input type="checkbox"> In stock</label>
</div>

The engine is tested against both examples.

How to fix it

Point the attribute at the id of the element it drives, and make that element a popover with the popover attribute, or a <dialog> for the dialog commands.

Check your own pages

This rule runs in every pour audit: the browser extension, the bookmarklet, the command line and the editor. Get pour, free.