Skip to content
FunnelGuard

Fix guide by FunnelsGuard

Keyboard trap in checkout or modal: how to find and fix it

OPS-375High impactCould addBy FunnelGuardPublished Updated
On this page

What this issue is

A keyboard trap is when someone using only a keyboard (Tab, Shift+Tab, Enter, Esc) moves focus into a part of the page and cannot move out again. Focus is the highlight that shows which element will react to the next key press.

It is a failure of WCAG success criterion 2.1.2 (No Keyboard Trap). Common places are cookie banners, newsletter popups, cart drawers, payment iframes, embedded booking widgets and chat windows.

Why it costs you leads or sales

People who rely on a keyboard include screen reader users, people with motor disabilities and power users who avoid the mouse. If focus gets stuck, they cannot pay, submit the form or even leave the popup. Most will abandon the page.

It also adds legal and compliance risk, because keyboard operability is part of WCAG 2.2 AA, which many accessibility laws and demand letters refer to.

Where a keyboard trap breaks the journey
  1. Product pageAdd to cart works with Enter
  2. Cart drawer opensFocus moves into the drawer
  3. Focus stuckTab loops, Esc does nothing, no reachable close button
  4. Payment stepCannot be reached by keyboard
  5. Order confirmedSale never happens

The visitor reaches checkout but focus stays stuck in a popup, so later steps are never reached.

Keyboard-only visitors who complete checkoutExample numbers
Keyboard-only visitors who complete checkout (example)Mouse visitors: 60 %; Keyboard visitors, trap present: 0 %; Keyboard visitors, trap fixed: 58 %0234660058Mouse visitorsKeyboard visitors, tr…Keyboard visitors, tr…%

Example: illustrative numbers showing how a trap can cut completions for keyboard-only visitors. Not real data.

How to check if your site has it

You only need a keyboard and about ten minutes. Unplug or ignore the mouse and walk through your main funnel.

Manual keyboard test
  1. Start at the top of the page

    Click the address bar, then press Tab. You should see a visible focus outline move through links and buttons in a logical order.

  2. Open every popup and drawer

    Trigger the cookie banner, newsletter popup, cart drawer, size guide and chat widget using Enter or Space on their buttons.

  3. Try to leave each one

    Press Esc, then Tab and Shift+Tab through the content. You should be able to reach a close button and activate it.

  4. Check focus return

    After closing, focus should land back on the button that opened the dialog, not at the top of the page or on nothing.

  5. Walk through checkout

    Move through address, shipping and payment fields. Pay special attention to embedded payment iframes, address autocompletes and date pickers.

  6. Repeat with a screen reader

    Use VoiceOver on Mac or iOS, NVDA on Windows (free) or TalkBack on Android to confirm the dialog is announced and can be exited.

For a quick automated pass, the free browser extensions axe DevTools and WAVE, and Lighthouse in Chrome DevTools, catch some focus and ARIA problems. They cannot prove there is no trap, so keep the manual test.

How to fix it

The correct pattern is the same everywhere: move focus into the dialog when it opens, keep Tab inside while it is open, close on Esc, and send focus back to the trigger. The way you apply it depends on your platform.

Fix by platform
  1. Identify the source

    Disable popup, cookie and chat plugins one at a time on a staging copy and retest to find which one traps focus.

  2. Update or change settings

    Update the plugin and theme. Look for options such as 'Close on Esc' or 'Enable accessibility mode' in the popup plugin settings.

  3. Replace if needed

    If the plugin cannot be dismissed by keyboard, switch to one that supports it or contact the developer.

Accessible modal using the native dialog elementhtml
<button id="open-cart">Open cart</button>

<dialog id="cart" aria-labelledby="cart-title">
  <h2 id="cart-title">Your cart</h2>
  <!-- cart content -->
  <button id="close-cart" type="button">Close</button>
</dialog>

<script>
  const dialog = document.getElementById('cart');
  const opener = document.getElementById('open-cart');
  opener.addEventListener('click', () => dialog.showModal());
  document.getElementById('close-cart').addEventListener('click', () => dialog.close());
  // Esc closes a modal dialog by default.
  // Focus returns to the opener when the dialog closes in modern browsers;
  // this makes it explicit for older ones.
  dialog.addEventListener('close', () => opener.focus());
</script>
Popup behaviour

With a keyboard trap

  • Focus loops inside the popup
  • Esc does nothing
  • Close icon is a div that cannot be focused
  • Visitor cannot reach checkout

Fixed

  • Esc closes the dialog
  • Close is a real button reachable with Tab
  • Focus returns to the opening button
  • Visitor continues to payment

How to confirm it's fixed

Retest checklist
  • Every popup, drawer and banner can be opened with Enter or Space
  • Esc closes each dialog
  • A visible close button is reachable with Tab
  • Focus returns to the trigger after closing
  • Tab never gets stuck in a loop outside an open dialog
  • Payment and address fields can be reached and completed by keyboard
  • The test passes on desktop Chrome, Safari and Firefox, and on mobile with an external keyboard or screen reader
  • axe DevTools or Lighthouse shows no new focus or ARIA errors

How to prevent it happening again

Traps usually come back when someone adds a new popup, updates a theme or installs a plugin. Build a keyboard test into your release routine.

How a trap sneaks back in (Example)
  1. Week 1

    Example: you fix the cart drawer and test it by keyboard.

  2. Week 4

    Example: marketing adds a new email popup through a plugin or tag manager.

  3. Week 4

    Example: the popup has no close button reachable by keyboard.

  4. Week 8

    Example: a complaint or audit finds the trap.

Habits that keep it fixed
  • Run the keyboard test after every theme, plugin, app or tag change
  • Add 'works with keyboard only' to your launch checklist for new popups and forms
  • Ask vendors of chat, booking and payment widgets for their accessibility conformance report
  • Run an automated accessibility scan monthly and a manual pass quarterly
  • Keep a short list of every overlay on the site and who owns it

How FunnelGuard handles this

FunnelGuard does not check for keyboard traps today. It is a possible future check, not a current feature, so you should not rely on FunnelGuard to find one.

What FunnelGuard does catch nearby: a robot visitor runs your real journeys (lead forms, checkouts, booking and chat buttons) on a schedule and checks each step. If a popup or broken script stops the journey from completing, or a tracking hit or test lead goes missing, you get one alert after a second-region re-check, with a screenshot and a likely cause. That can reveal a blocked step, but it will not tell you that a keyboard user is trapped.

To watch for keyboard traps, use the manual test above, add axe DevTools or Lighthouse to your release routine, and test with a screen reader at least quarterly. You can start with a free FunnelGuard plan (1 site, 2 journeys, daily checks, no card) to monitor that your funnel still completes.

Questions people ask

What is a keyboard trap in a checkout or modal?

A keyboard trap is when focus enters a modal, popup or checkout widget and the person cannot leave using Tab, Shift+Tab or Esc. It fails WCAG 2.1.2 (No Keyboard Trap) and blocks keyboard and screen reader users from completing purchases.

Why can't I tab out of my popup?

Usually the popup has no focusable close button, ignores the Esc key, or its script keeps focus looping without an exit. Make the close control a real button, let Esc close the dialog, and return focus to the element that opened it.

Is keeping focus inside a modal a keyboard trap?

No. Keeping Tab inside an open modal is the expected behaviour. It becomes a trap only when the user has no keyboard way to close the modal and return to the page.

How do I test my checkout for keyboard traps?

Put the mouse aside and press Tab, Shift+Tab, Enter, Space and Esc through the whole journey. Open every popup, drawer and payment step and confirm you can always move on or close. Then repeat with a screen reader such as NVDA or VoiceOver.

Does the HTML dialog element prevent keyboard traps?

Used with showModal(), the native dialog element handles focus containment and closes on Esc, which avoids most traps. You still need a visible close button and must test any third-party content inside it.

Can a payment iframe cause a keyboard trap?

Yes. If an embedded payment or booking iframe captures focus and does not release it, keyboard users cannot move past it. Test it by keyboard and report the problem to the vendor if you cannot control the code.

Does FunnelGuard detect keyboard traps?

No. FunnelGuard does not check for keyboard traps yet, though it is a possible future check. It does run your real journeys on a schedule and alerts you when a step fails, but you need a manual keyboard test or accessibility tools for this issue.

Can a keyboard trap lead to an accessibility lawsuit?

It can add risk, because keyboard operability is part of WCAG 2.2 AA, which many accessibility laws and complaints reference. Fixing traps and documenting your testing reduces that exposure, but this is not legal advice.

Does FunnelGuard catch this?

Could add

Not checked yet: could be added to FunnelGuard.

Stop finding out from your customers

FunnelGuard runs your real forms and checkouts on a schedule, checks the tracking and the leads behind them, and alerts you once, with a screenshot. Try any paid plan free for 3 days.