-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clicking another shadowed element inside the focus trap will deactivate the focus trap #959
Comments
@driskull Thanks for the detailed report and all your analysis so far! It's very helpful. My first thought is that this is actually an issue with tabbable, not focus-trap, since focus-trap relies on what tabbable finds in each of the containers its given to determine what's in or out of the trap: https://github.com/focus-trap/focus-trap/blob/master/index.js#L380-L400 I'm guessing tabbable isn't finding that other light shadow element you've inserted in the trap for some reason, and since your trap is configured to deactivate on click outside, it deactivates when you click on it (it treats that shadow element as being outside the trap). If you could dig further into tabbable and see if that's the case, it would be a big help! Pay close attention to getCandidatesIteratively() as that should be getting used by tabbable in this case since you're using shadow DOM elements with focus-trap (assuming, also, you've configured focus-trap's |
@stefcameron I'll dig into the However, it does seem to be an issue with Seems like focusTrap shouldn't be deactivating in this case. |
@stefcameron it actually just seems to be a With the tabbableOptions: {
getShadowRoot: true
}, So it just seems to be a |
@driskull Thanks for investigating further and for the draft PR. I'll check this out. |
@driskull So the problem is that we're slotting non-focusable, non-tabbable text nodes into those custom elements you've added, when clicking on either one, it's actually the If I carefully click on one of the extreme corners of the "Shadow Button" you've added to the demo, the trap remains active because the click is registered on the shadow If I slot a So some additional check is needed in https://github.com/focus-trap/focus-trap/blob/master/index.js#L185-L198 when the |
@stefcameron Yep, that's exactly what I was seeing as well. This did seem to fix it but I'm not sure if its ideal. tabbableNodes.find((node) => node === element || node.contains(element)) |
Good to know we're seeing the same thing. Your suggestion would work, but only as long as there are no nested shadow DOMs since What we need is |
Well, actually your suggestion wouldn't hurt to be added to the second check. But we'd still need the exhaustive 3rd check as a fallback. |
Is there no way to get the composedPath of the click event and check to see if the composedPath contains the element in question? That would solve it in all cases. Something like |
Interesting. In I think your suggestion would work since that element is effectively a child of that shadow and part of the listed path! Just need to add the Is this something you want to add to your PR then? Just want to make sure we don't double-up on the same work. We'd also need to add a And I noticed that the spanned slot in your PR is missing a closing I think that would do it. |
@stefcameron updated the PR. Let me know what needs to be changed. Thanks 🍻 |
I appreciate your updates, thank you! Left a quick comment on the PR. |
@driskull Thanks for your work on that PR. Now that it's merged, I'll publish the fix shortly. 😄 |
Awesome! Thanks for the help with getting this in |
Published in focus-trap v7.4.2 |
When the following settings are set, clicking another shadowed element inside the focus trap will deactivate the focus trap when it shouldn't.
Clicking the "Light Dom Button" was just to verify a normal button doesn't deactivate the focus trap. However, a custom element button with a shadowRoot does deactivate the focus trap.
Example
Example demo patch to see problem
example commit: driskull@1be26a4
I tracked the issue down to this function
focus-trap/index.js
Lines 185 to 196 in b781078
It seems to be having a problem with the slotted
<slot>
element.This seems to fix it but I'm not sure if its the right solution...
I did notice that even elements that are not "tabbable" in this scenario are deactivating the focus trap. driskull@ade43e5
Let me know how I can help with this issue. :)
The text was updated successfully, but these errors were encountered: