Cannot read property 'ownerDocument' of null
I'm getting this error thrown by the tabbable library which focus-trap-react depends on by way of focus-trap. At first I thought this might be a jest/enzyme problem but I'm also seeing it in non-test code.
TypeError: Cannot read property 'ownerDocument' of null
at tabbable (index.js:21)
at updateTabbableNodes (index.js:267)
at Object.activate (index.js:72)
at FocusTrap.componentDidMount (focus-trap-react.js:55)
I also noticed that the line that's throwing this error is an older version than your most recent update of tabbable...perhaps a version update would help? I haven't tested that yet, but I would love any input you have.
I've used this library before and had really great results with it, so thanks!
Same here, I upgraded from 4.0.1 to 6.0.0 and facing this issue
Also happening in 5.0.1
@lukeschunk can you please be more specific about the situation in which this behavior is happening? This does not happen universally — for example, I'm not seeing it in the demos — so I think we need to identify what you and @pradel are doing that triggers the error.
I get the same error when trapping a SemanticUI react Modal
I think the source of the error is https://github.com/davidtheclark/tabbable/blob/b8ceed435664fdf51b5f70729ab50c63e1877190/index.js#L142. Somehow in special cases we're arriving at that point and node is null. Probably adding an additional check would stop the error — but it would still be nice to understand why node might be null at that point.
There's a chain of libraries to update here — tabbable, focus-trap, then this one.
I haven't had the chance to take a look yet, but I will when I can. 💥
I found that if the child of FocusTrap isn't a HTML element then this error pops up.
E.g
Errors with Cannot read property 'ownerDocument' of null
<FocusTrap>
<Fragment>
{/* ...content */}
</Fragment>
</FocusTrap>
Works
<FocusTrap>
<div>
{/* ...content */}
</div>
</FocusTrap>
You can see an example here. Make sure its set to current module view. And checkout will-error.js & works.js
I just ran in to this issue and @jimmaaay's fix works. Is it possible to enable the use of <Fragment> also?
import FocusTrap from "focus-trap-react";
import { CSSTransition } from "react-transition-group";
<FocusTrap>
<CSSTransition>
<div>
{/* ...content */}
</div>
</CSSTransition>
</FocusTrap>
I got the same error in this way. is there anyway to define the ownerDocument on FocusTrap props?
I think https://github.com/focus-trap/focus-trap-react/pull/139 fixed it
@rivajunior That would be awesome! I just published #139 in 8.1.1.
Closing very old issues. There have been a lot of improvements to the library (and tabbable and focus-trap) since I took over in July 2020, and this may be fixed now. If it's still an issue with the current release, feel free to re-open.