Rule
Unexpected context change
Changing or focusing a control must not unexpectedly change context.
- Rule
on-input-navigation- WCAG 2.2
- 3.2.2 On Input (opens in a new tab) (Level A)
3.2.1 On Focus (opens in a new tab) (Level A) - Severity
- Serious
What it checks
The rule reads inline event handlers: onchange and oninput on <select>, <input> and <textarea>, and onfocus on any element. It looks for handler code that navigates or submits: an assignment to location or location.href, a call to location.assign, replace or reload, a form submit or requestSubmit, or window.open. Code that only reads the location, for example to send it to analytics, does not count.
Handlers a script adds with event listeners cannot be read from the page, so the rule sees only the inline kind. A page without inline handlers gives it nothing to look at.
When a person decides
The rule never fails. Handler code shows that a navigation can happen, not that it always does: it may run only for one value, or after a confirmation. A change of context when an element merely receives focus fails 3.2.1, so a navigating onfocus asks for a check of what happens when focus lands. A navigating change handler is allowed by 3.2.2 when users are told beforehand, so it asks for a check of the text before the control.
Example
Sent to review
<label for="country">Choose a country site</label>
<select id="country" onchange="location.href = this.value">
<option value="/uk/">United Kingdom</option>
<option value="/ie/">Ireland</option>
</select>
Passes
<form action="/choose-site">
<label for="country">Choose a country site</label>
<select id="country" name="country" onchange="showFlag(this.value)">
<option value="uk">United Kingdom</option>
<option value="ie">Ireland</option>
</select>
<button>Go</button>
</form>
The engine is tested against both examples.
How to fix it
Navigate from an explicit button, such as Go, rather than from the change or focus event. If a change must navigate, say so in text before the control.
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.