v5.3.0 breaks literally all of our usage of `tabbable` 😅 when called on a node not attached to the document
See original GitHub issueThe change to use getClientRects().length
completely breaks this library for us: https://github.com/focus-trap/tabbable/pull/604
We use tabbable
when initializing dialogs, to find candidate element(s) to auto-focus when the dialog appears. These dialogs are React components and the call to tabbable()
occurs during the componentDidMount
lifecycle method. At that moment, the DOM elements we want to traverse using tabbable
are fully formed, but they are not yet attached to the document. So getClientRects().length
always returns 0, and thus every single one of our calls to tabbable
fails. (At this library level, we have no way to control when the dialog is actually attached to the document.)
Could this change be reverted, or can we scope it to only be used when document.body.contains(node)
?
Issue Analytics
- State:
- Created a year ago
- Comments:39 (24 by maintainers)
Top GitHub Comments
I agree that the current behavior should be preserved as there are probably many that depends on it, but would change next major version to swap the default behavior to reflect the fact that detached nodes are not actually tabbable/focusable, with an option to ignore
isHidden
on detached nodes.Love this discussion! 😆 Glad we can laugh a bit along the way, even with memes. Yes, what an adventure we are on in software land…
So I think we have solution, which is to assume that a detached node is visible. That should restore the old behavior, while letting us keep using the new optimization with
getClientRects()
when it’s attached.I will update my PR tomorrow accordingly and will get a patch out.