A cart drawer is the panel that slides in when a shopper adds something to their cart. It is convenient for mouse users and often confusing for keyboard and screen reader users: focus stays on the page behind, or gets stuck inside the drawer with no way out. Because the drawer sits between "add to cart" and checkout, a broken one can stop a sale. Here is how to test yours and what to fix.
Two ways a cart drawer goes wrong
- Focus escapes. The drawer opens visually, but pressing Tab moves through the page hidden behind it. A keyboard user can't reach the "Checkout" button, and a screen reader user may not know the drawer opened.
- Focus is trapped. The keyboard moves into the drawer but there is no way back out: Escape does nothing and the close button can't be reached. WCAG 2.1.2 says that if focus can be moved into a component with the keyboard, it must be possible to move it away again with the keyboard (Understanding Success Criterion 2.1.2: No Keyboard Trap (W3C WAI)).
The fix for both is the same pattern: treat the drawer as a modal dialog while it is open.
Step 1: Test your drawer in two minutes
- Go to a product page, press Tab until "Add to cart" is focused and press Enter.
- Does focus move into the drawer (for example to the drawer itself or its close button)? Is it visible?
- Press Tab repeatedly. Does focus stay inside the drawer and loop back to the start, or does it disappear behind the drawer?
- Press Escape. Does the drawer close?
- After closing, is focus back on the "Add to cart" button (or the cart icon you used to open it)?
If any answer is no, the drawer needs work. The same test applies to mobile menus, search overlays and quick-view windows.
What a correct drawer does
The W3C's ARIA Authoring Practices describe the expected keyboard behaviour for a modal dialog (Dialog (Modal) Pattern (W3C WAI-ARIA Authoring Practices Guide)):
- When it opens, focus moves to an element inside it.
- Tab and Shift+Tab move only between the elements inside, wrapping from last to first and first to last.
- Escape closes it.
- When it closes, focus returns to the element that opened it.
Shopify's free Dawn theme is a useful reference. Its cart drawer markup has role="dialog", aria-modal="true" and an aria-label with the cart title, and its close buttons are labelled (snippets/cart-drawer.liquid in Shopify's Dawn theme (GitHub)). Its script remembers which element opened the drawer, closes on Escape, keeps focus inside while it is open and returns focus when it closes (assets/cart-drawer.js in Shopify's Dawn theme (GitHub); assets/global.js (trapFocus and removeTrapFocus) in Shopify's Dawn theme (GitHub)). If your theme is based on Dawn and the drawer misbehaves, compare your copy with these files: an app or a customisation may have changed it.
Step 2: The simplest fix for custom code: the dialog element
If you or a developer are building or rebuilding a drawer, the HTML <dialog> element does most of the work. When opened with showModal(), the browser makes the rest of the page inert, so focus can't wander behind it, and Escape closes it (<dialog>: The Dialog element (MDN Web Docs)). You still need to send focus back to the opener when it closes.
<button type="button" class="cart-toggle" aria-haspopup="dialog">
Cart <span class="cart-count">2</span>
</button>
<dialog class="cart-drawer" aria-labelledby="cart-drawer-title">
<h2 id="cart-drawer-title">Your cart</h2>
<button type="button" class="cart-close">Close cart</button>
<!-- cart items -->
<a href="/checkout" class="button">Check out</a>
</dialog>
<script>
const drawer = document.querySelector('.cart-drawer');
let opener = null;
document.querySelector('.cart-toggle').addEventListener('click', (e) => {
opener = e.currentTarget;
drawer.showModal();
});
drawer.querySelector('.cart-close').addEventListener('click', () => drawer.close());
// Escape also closes a modal dialog; either way, send focus back.
drawer.addEventListener('close', () => opener && opener.focus());
</script>Style the dialog as a side panel with CSS (fixed position, full height, right edge). If you use a JavaScript framework or an older drawer you can't replace, the inert attribute on the rest of the page achieves the same "nothing behind me is focusable" effect (inert attribute (MDN Web Docs)).
Step 3: Fixes for existing Shopify drawers
- Theme drawer broken after an app install: some cart and upsell apps replace the theme drawer with their own. Turn the app's drawer off temporarily and repeat the test. If the theme's drawer works, the app is the cause; contact its developer.
- No close button name: an "X" icon needs an accessible name such as "Close cart". See icon buttons with no name.
- Cart count changes silently: when items are added, a short status message ("Added to cart, 2 items") helps screen reader users. WCAG 4.1.3 uses a shopping cart update as an example of a status message that should be announced without moving focus (Understanding Success Criterion 4.1.3: Status Messages (W3C WAI)).
Step 4: Fixes for WooCommerce mini-carts
WooCommerce's classic mini-cart template already labels each remove link with the product name, for example "Remove Blue T-shirt from cart" (cart/mini-cart.php template (WooCommerce, GitHub)). Problems usually come from the theme or plugin that wraps it in a drawer or dropdown. Apply the same test and the same dialog pattern. If a plugin provides the drawer, check its settings or ask the developer; theme changes belong in a child theme.
Check your own store in a minute or two. Our free scanner opens your homepage, a collection page, a product page and your cart in a real browser and lists the problems it can detect automatically, in plain English.
Common questions
Should the cart open as a drawer at all?
That is a design choice. A drawer that follows the dialog pattern works well. Sending shoppers to the cart page instead is also fine and avoids the problem entirely. Many themes have a setting for this; Dawn, for example, lets you choose a drawer, a cart page or a pop-up notification (config/settings_schema.json (cart type setting) in Shopify's Dawn theme (GitHub)).
Does trapping focus inside the drawer break WCAG 2.1.2?
No, as long as the shopper can leave with the keyboard, for example with Escape or the close button. Keeping focus inside an open modal is the expected pattern (Dialog (Modal) Pattern (W3C WAI-ARIA Authoring Practices Guide)); a trap is when there is no keyboard way out (Understanding Success Criterion 2.1.2: No Keyboard Trap (W3C WAI)).
Will the scanner find this?
Partly. Automated rules can find a missing name on the close button, but they can't tell whether focus moves correctly. That is why the keyboard test matters.
Technical fixes, not legal advice. This guide explains website accessibility from a technical point of view. We are not a law firm, and nothing here is legal advice. No scan, fix or guide can guarantee legal compliance, the outcome of any demand letter or lawsuit, or protection from future claims. If you have received a legal claim, please consult a qualified attorney about it.
Sources
- Dialog (Modal) Pattern (W3C WAI-ARIA Authoring Practices Guide)
- Understanding Success Criterion 2.1.2: No Keyboard Trap (W3C WAI)
- Understanding Success Criterion 4.1.3: Status Messages (W3C WAI)
- <dialog>: The Dialog element (MDN Web Docs)
- inert attribute (MDN Web Docs)
- snippets/cart-drawer.liquid in Shopify's Dawn theme (GitHub)
- assets/cart-drawer.js in Shopify's Dawn theme (GitHub)
- assets/global.js (trapFocus and removeTrapFocus) in Shopify's Dawn theme (GitHub)
- config/settings_schema.json (cart type setting) in Shopify's Dawn theme (GitHub)
- cart/mini-cart.php template (WooCommerce, GitHub)