The Cart Drawer Focus Trap: A Keyboard Test Every Store Can Run

Slide-out cart drawers trap keyboard users when focus escapes behind the drawer or never returns to the bag button. The test takes five minutes and needs no tools.

The drawer opens, and focus stays behind it

A slide-out cart is the default pattern on Shopify themes, and its most common accessibility defect is invisible on screen. A keyboard user tabs to the bag button, presses enter, the drawer slides in, and their focus stays on the page behind it. The next twenty tab presses walk through the dimmed homepage, links and all, while the drawer they opened sits unreachable. Some drawers do the opposite on close: focus is dumped at the top of the document, and the shopper starts the page again from the first link.

Related reading: The Checkout Discount Code Field: The Label Screen Readers Skip and Checkout Progress Steps: The Step Indicator Screen Readers Cannot Follow, plus The Checkout Country Selector: The Dropdown Keyboard Users Cannot Escape.

WCAG 2.2 has criteria for each half of this. Criterion 2.4.3, Focus Order, requires that focus moves in an order that preserves meaning and operability, which sending focus into a hidden background page plainly does not. Criterion 2.1.2, No Keyboard Trap, cuts the other way: a drawer that traps focus must still let the user leave with the escape key or the close button. A good drawer is a managed loop, not a trap and not a leak.

The five minute test

Unplug the mouse. Tab to the bag button and open the drawer. Your first tab press inside should land on the close button or the first drawer control, not on a background link. Keep tabbing: focus should cycle through the drawer's quantity controls, checkout button, and close button, and the visible focus outline should never disappear behind the overlay. Press escape: the drawer closes and focus returns to the bag button you opened it from.

Then run the failure cases. Empty the cart from inside the drawer and see where focus goes when the checkout button vanishes; it should land somewhere sensible, usually the empty message or the close button, not the document top. Add an item from a product page and check the drawer does not steal focus mid task unless it opens, in which case it must take focus properly. Each of these is a two minute check, and together they cover the defects real shoppers report.

Why themes ship it broken

Most drawer code is written and reviewed with a mouse. The visual result is identical whether focus is managed or not, so the defect survives design review, QA, and launch. It is usually found by a customer, or by an audit the store commissions after a complaint. The WebAIM Million data puts the average home page's detectable errors in the dozens, and interactive widgets layered over pages are a reliable contributor.

The fix is rarely structural. Move focus into the drawer on open, keep it cycling while the drawer is open, close on escape, and return focus to the opener on close. That is a small, well understood pattern, documented in the WAI ARIA Authoring Practices for modal dialogs. A drawer that behaves like a modal must be built like one, and most are a few lines of code away from it.

Frequently asked questions

What should happen to keyboard focus when a cart drawer opens?

Focus should move into the drawer, usually to its close button or first control, and cycle within the drawer while it is open. When the drawer closes, focus should return to the element that opened it, normally the bag button, so the shopper continues from where they left off.

Is a cart drawer a modal dialog for accessibility purposes?

Functionally yes, when it overlays the page and blocks interaction with it. It should follow the modal pattern: focus contained while open, escape to close, and focus restored on close. If the background page is still tabbable behind the drawer, the pattern is broken.

How do I test a cart drawer without a screen reader?

Use the keyboard alone. Tab in, confirm focus enters and cycles inside the drawer, check the focus outline stays visible, press escape, and confirm focus returns to the bag button. Then empty the cart inside the drawer and check focus lands somewhere sensible.

Which WCAG criteria cover cart drawer focus?

Criterion 2.4.3 Focus Order covers focus moving into the background page, and 2.1.2 No Keyboard Trap covers a drawer the user cannot leave. Criterion 2.4.7 Focus Visible applies to the outline disappearing behind the overlay, a common drawer defect.