CodePark/ questions / Focus management
START PRACTICINGPRACTICE
Frontend question · Accessibility › Focus management

In a to-do list, the user presses the focused "Delete" button on an item, and the item is removed from the DOM. What should happen to focus?

Your code moves focus to a sensible place, such as the next item, the previous item, or the list heading

When the focused element is removed, focus is lost and document.activeElement becomes <body>. The user loses their place, and a screen reader may start reading from the top. So your code should move focus on purpose to the next item, the previous one, or the list heading if the list is now empty.

"The browser moves focus to the next item automatically" is the tempting wrong answer. Browsers don't do that. "Falls to the body, which is fine" is wrong, because losing your place after every delete makes the list very slow to use.