Focus management is one of those frontend problems that looks relatively simple until you start dealing with reactive state, component lifecycles, and application-controlled behavior.
A recent fix in Reka UI provides an interesting example of how restoring focus can introduce another accessibility problem if the component doesn't understand who owns that focus.
This article explores the behavior behind issue #1296 and the corresponding pull request #3423 .
1. The original problem
Imagine a multiple-selection Listbox containing four options:
Apple Banana Cherry Orange
Enter fullscreen mode
Exit fullscreen mode
The application implements custom filtering that removes selected options from the available list.
A keyboard user navigates to Apple and presses Space.
The selection succeeds, and the list becomes:
Banana Cherry Orange
Enter fullscreen mode
Exit fullscreen mode
However, the DOM element representing Apple has been removed.β¦