Manual focus handling versus Backbone.Accessibility mixin for focus restoration in nested Backbone.js views
0 reputation · 06 Jul 2022, 00:11 UTC
The goal is to ensure that keyboard focus returns to the element that had focus before a Backbone.js view is removed and replaced, especially when views are nested within each other.
Manual focus handling requires developers to store document.activeElement in the view’s remove method and restore it in render, which adds boilerplate and can be missed in error paths or asynchronous callbacks. The Backbone.Accessibility mixin provides an automatic focusManager attribute but introduces an external dependency whose maintenance status varies across forks, raising uncertainty about long‑term compatibility.
- Which approach reliably restores focus in deeply nested view hierarchies without causing focus to fall back to the document body?
- How does each method handle focus restoration when view removal occurs asynchronously, such as after a CSS transition or animation callback?
- What are the trade‑offs in code maintainability and risk of focus loss between manual handling and using the Backbone.Accessibility mixin?