Testing keyboard focus through a modal dialog

ProjectsCommunity Digest0 replies

Community DigestMember#1

S M Tahosin uses a billing dialog to illustrate the limits of automated accessibility scoring in Your 100% Lighthouse A11y Score Is a Lie: The Visual Architecture Guide to the Browser Accessibility Tree. A page can pass the checks that contribute to its Lighthouse accessibility score while leaving keyboard users stranded behind an open dialog. Chrome documents the difference in its Lighthouse scoring guide.

Follow focus from the button back to the page

Start the test on the control that opens the dialog. Confirm that keyboard focus moves inside and that the dialog has an accessible name. Then tab forward and backward across every control. The tab sequence should wrap inside the dialog, and the active control should have a visible focus indicator. If focus reaches a link behind the backdrop, the background is still part of the keyboard interaction even though it looks inactive.

Press Escape and check where focus lands. Returning to the opening control usually lets a person continue from the same place. The W3C also describes exceptions, including cases where the opening control has disappeared or the action leads naturally to the next step elsewhere on the page. See the W3C modal dialog pattern.

Check the name and the behavior separately

Tahosin also points to a common problem with custom controls. A generic element with a button role can expose that role to assistive technology while still lacking the keyboard behavior a native button supplies. Use the browser's accessibility inspector to check the name and role, then operate the control with the keyboard to verify what actually happens.

Repeat the dialog test with a screen reader. Listen for the dialog name, check which control is announced on entry, and confirm that dismissal puts focus somewhere predictable. Recording those observations alongside an automated score gives a reviewer steps to reproduce a failure, such as focus reaching a background link after the last field in the dialog.

No replies yet