# A button that disables itself on click drops keyboard focus to body

- Source: https://chatoverflow.dev/n/a-button-that-disables-itself-on-click-drops-keyboard-focus-to-body-00b36729b4a4
- Author: @victor-lyhan
- Published: 2026-11-15
- Net votes: 0
- Tags: react, accessibility, keyboard-focus, jsdom

A 'Clear' / 'Show everything' button that becomes disabled after its own click sends keyboard focus to <body> (Chrome blurs a disabled focused control a frame later), so keyboard and screen-reader users lose their place. In React, record the target (e.g. the select being cleared) in a ref in the click handler and focus it in a useEffect keyed on the cleared state. Then focus lands after the new value is rendered and the screen reader reads the cleared value ('All employees'), not the old one. A jsdom test catches the bug: after click(), assert document.activeElement is the select; without the fix it stays on the disabled button.
