The Cart Drawer Steals Focus and Never Gives It Back

Open the drawer and focus goes nowhere

Activate the cart button on most stores and a drawer slides in from the right, visually obvious and programmatically silent. Keyboard focus stays on the button behind the drawer, or drops to the top of the document. The shopper tabs forward and cycles through the page underneath a panel they cannot see into. Nothing about that sequence announces itself, and no automated scan flags it, because the drawer markup is perfectly valid HTML in the wrong order.

Two criteria govern this. WCAG 2.4.3 Focus Order, Level A, requires that focusable elements receive focus in an order that preserves meaning and operability. WCAG 2.4.7 Focus Visible, Level AA, requires a visible indicator wherever focus lands. A drawer that opens without moving focus fails the first in spirit and usually the second in practice, because the indicator sits on a button the drawer now covers, which also brushes against 2.4.11 Focus Not Obscured, new in WCAG 2.2.

The pattern that passes

The working pattern is the modal dialog pattern, applied only while the drawer is open. On open, move focus to the drawer's first focusable element or its heading with tabindex set to minus 1. Trap the tab cycle inside the drawer while it is open. On close, whether by the close button, the Escape key, or a click on the overlay, return focus to the cart button that opened it. That return trip is the step implementations skip, and it is the step keyboard users feel most: without it, closing the drawer dumps them at the top of the page to tab through the entire header again.

Escape closing the drawer is not optional garnish. It is part of the dialog pattern in the WAI ARIA Authoring Practices, and shoppers who use switches or voice control rely on the same predictable exits. We covered the related announcement problem in Checkout Address Fields in the Wrong Order Break the Whole Form: a drawer that opens silently and closes silently leaves assistive technology users with no account of what happened to their cart.

Test it in ninety seconds

Put the mouse away. Tab to the cart button and open the drawer with Enter. Note where the focus indicator is. If you cannot see it, that is finding one. Tab through the drawer: you should reach the quantity controls, the remove links, and checkout without ever landing on the page behind. Press Escape: the drawer should close and the indicator should be back on the cart button. Then repeat with a screen reader running and listen for the drawer being announced as a dialog with a name, something like Shopping cart, not just a stream of links arriving unannounced.

Fix priority follows harm. The focus return on close is a one line change in most drawer scripts and removes the worst harm. The trap matters next. The announcement matters throughout, because a drawer a shopper cannot perceive as open is a drawer they cannot deliberately close.

Frequently asked questions

Does a cart drawer have to trap keyboard focus?

While it behaves as a modal, covering the page and blocking interaction behind it, yes. Focus should move into the drawer on open, cycle inside it, and return to the cart button on close. If the drawer is non modal and the page stays usable, a trap is not required, but focus still needs a logical order.

Which WCAG criteria cover cart drawer focus?

Focus Order 2.4.3 at Level A, Focus Visible 2.4.7 at Level AA, and in WCAG 2.2, Focus Not Obscured 2.4.11, which covers the case where the drawer hides the focused element behind it. The dialog behaviour itself follows the WAI ARIA Authoring Practices pattern.

Why does focus return matter when the drawer closes?

Without it, the browser drops focus to the document body and the shopper restarts from the top of the page. Returning focus to the element that opened the drawer keeps the shopper's place, which is the whole point of the pattern.

Can an automated scan catch drawer focus problems?

Generally no. Scans check the static markup, and drawer failures live in the sequence of interactions: open, tab, escape, close. Only a keyboard walkthrough, ideally with a screen reader pass after it, exercises that sequence.