focus-lock icon indicating copy to clipboard operation
focus-lock copied to clipboard

Focus breaks on focusable element with shadowRoot

Open SamuelTilly opened this issue 1 year ago • 4 comments

We use a web-component library that has elements that both contains a shadowRoot and expects to receive focus with tabIndex.

image

getActiveElement function skips over elements that hold focus and also has a shadowRoot.

I'm not entirely sure how the internals of this library is supposed to work, but after removing the part about shadowRoot from getActiveElement focus works as expected for us. Perhaps it would need to validate that the element is not focusable as well as having .shadowRoot property.

SamuelTilly avatar Nov 30 '23 09:11 SamuelTilly

To clarify - problem is related to focusable shadow root. But what exactly is not working right? Ie doing X instead of doing Y..

theKashey avatar Dec 02 '23 09:12 theKashey

The expected behaviors would be that ids-button gains focus, but instead focus is reset to the first focusable element.

<button>First</button> 
<button>Second</button>
<ids-button>Third</ids-button tabindex="0"> <!-- instead of this gaining focus on tab, the "First" button get's focus. -->
<button>Fourth</button>

SamuelTilly avatar Dec 04 '23 14:12 SamuelTilly

hm, the logic right now is "do nothing if focus is inside parent component". If focus is triggered, then ids-button is not "focusable" in the usual terms. Worth investigation as this is not just a "bug", but a total blocker for someone.

theKashey avatar Dec 05 '23 05:12 theKashey

Thank you! I wish I had more time to investigate this a bit further, but for now we have created a patch that seems to work for us, might break other things, so I don't feel confident in providing a PR. Here is the patch https://gist.github.com/SamuelTilly/70fdbe33e55aafb6cebeba2ae3127ab0

I don't know if the slot element logic is necessary, but I guess it would not hurt either.

SamuelTilly avatar Dec 05 '23 09:12 SamuelTilly

This issue has been marked as "stale" because there has been no activity for 2 months. If you have any new information or would like to continue the discussion, please feel free to do so. If this issue got buried among other tasks, maybe this message will reignite the conversation. Otherwise, this issue will be closed in 7 days. Thank you for your contributions so far.

stale[bot] avatar Feb 03 '24 12:02 stale[bot]

This issue has been marked as "stale" because there has been no activity for 2 months. If you have any new information or would like to continue the discussion, please feel free to do so. If this issue got buried among other tasks, maybe this message will reignite the conversation. Otherwise, this issue will be closed in 7 days. Thank you for your contributions so far.

stale[bot] avatar Apr 09 '24 23:04 stale[bot]