Skip to content
easeweb
Search topics

Buttons that act on press and can't be cancelled

The button runs its action on pointerdown, so a press that lands on it by mistake takes effect at once, and sliding off before letting go can't stop it.

WCAG 2.2
SC 2.5.2A· new in 2.1
Required by
EN 301 549 (EU)
Broken addEventListener('pointerdown', addToBasket)
The accessibility problem illustrated: Reach, strength:I slid off, so why was it added?
01

The problem

People whose press lands on the wrong button can't take it back by sliding off before they let go

02

Try it

Press and hold Add to basket, and watch when the item goes in. Then slide off before you let go

Touching a button is not deciding; letting go is. That gap is how anyone who touches the wrong button, or only meant to scroll, changes their mind. The line under the shop names the event the page acted on. On a phone, also scroll the list starting on a button.

Broken Can you fix this?

BrokenThe action on pointerdown
Kitchen linen Basket (0)
  • Linen tea towel
  • Cotton apron
  • Oak chopping board
  • Enamel mug

A recreated demo. The broken version is intentionally inaccessible.

03

The fix

Run the action on click, not on press

Before
BrokenThe action on pointerdown
<button type="button" class="add">Add to basket</button>
What is wrong2 points
  • A wrong press can't be taken back. pointerdown fires for a mouse, a pen and a finger the instant they touch the button, so the item is added before the person can see what they pressed or move away.
  • Scrolling the list adds items. On touch, pointerdown also fires at the start of every scroll that begins on the button.

mousedown, touchstart and a framework's onMouseDown or onTouchStart fail the same way.

After
FixThe action on click
<button type="button" class="add">Add to basket</button>
How it is fixed2 steps
  1. Replace the pointerdown listener with the button's own click. The browser fires click only when the press and the release both happen on the button, so sliding off before letting go cancels it, and a touch that turns into a scroll never becomes a click.
  2. Delete the keydown listener. click also fires for Enter and Space on a focused button, for a screen reader's double tap and for voice control, so the separate keyboard code goes too.

This fixes the Before and passes 2.5.2. The click on a button that has already been released feels just as fast: the time between press and release is what the person spends deciding.

Why this fix: Use native HTML first

HTML and ARIA
04

Verify the fix

5 checks.

Test with: Mouse, Touch, Keyboard, Screen reader

0 of 5 checked

Record the OS, browser and assistive-technology versions, the build, the date, and the actual result of each step. Repeat after the shared button or card component changes.

Limits

This is a starting pattern, not a guarantee for every application. Some controls must act on the press because that is what they are, such as the keys of an on-screen keyboard or a musical instrument; WCAG treats those as essential. A small button can still be missed in the first place: tap targets too small and too close together covers its size. Test the complete journey on real touch devices as well as with a mouse.

This is a recreated teaching example, not a finding about a named client. The code is a starting pattern: test it in your own product. No completed assistive-technology test is claimed here.

EaseWeb service

Fixed it? Keep it from coming back.

I turn guides like this one into rules your coding agents follow and checks your CI runs. Then I retest by hand with a keyboard and screen readers, periodically.

See the service