• Success Criterion 2.1.4
  • Conformance level A

Keyboard Shortcut That Fires Even While Typing in a Field

2.1.4 — Character Key Shortcuts

Scenario

Setting

A pharmacy app's prescription-refill form

What’s wrong

Shortcut active while focus is in text inputs (typed letters trigger actions).

Example

document.addEventListener('keydown', (e) => {
  if (e.key === 'r') refillAllPrescriptions();
});
<!-- typing "prescriber" in the doctor-name field triggers "refill all" on every letter r -->

Why it matters

A patient typing their doctor's name into a text field accidentally triggers a bulk refill of every prescription whenever the name contains the letter "r."

How to test

Focus a text input field and type a letter that's also a shortcut elsewhere on the page: if the shortcut fires instead of (or in addition to) the letter being typed, it fails.

How to fix

Always exclude form fields from single-character shortcut handling; a shortcut should never fire from ordinary typing.

document.addEventListener('keydown', (e) => {
  const tag = e.target.tagName;
  if (tag === 'INPUT' || tag === 'TEXTAREA' || e.target.isContentEditable) return;
  if (e.key === 'r') refillAllPrescriptions();
});

Outcome

A patient types their doctor's name freely without triggering an unwanted bulk refill.

Who is affected

Keyboard users typing ordinary text, and speech-input users whose transcribed words contain the trigger letter, cause the action unintentionally.

Learn more