Skip to content
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

Tree component not working properly in shadow DOM #871

Closed
xdev1 opened this issue Aug 25, 2022 · 1 comment
Closed

Tree component not working properly in shadow DOM #871

xdev1 opened this issue Aug 25, 2022 · 1 comment
Assignees
Labels
bug Things that aren't working right in the library.

Comments

@xdev1
Copy link
Contributor

xdev1 commented Aug 25, 2022

Describe the bug

When the tree component is used in shadow DOM then the keyboard navigation is not working.

To Reproduce

Please try to use the keyboard navigation in the tree element of this demo and you will see that it is broken:
https://jsbin.com/zewifakuke/2/edit?html,output

Source of this bug

The bug can be found here:

const activeItemIndex = items.findIndex(item => document.activeElement === item);

Focused elements in the shadow DOM cannot be accessed by document.activeElement.
Just replace that code line in question with the following and everything will work again:

const activeItemIndex = items.findIndex(item => item.matches(':focus'));

[Edit] Something like this may also work, I guess:

const activeItemIndex = items.findIndex(
  item => item === (this.getRootNode() as unknown as DocumentOrShadowRoot).activeElement
);
@xdev1 xdev1 added the bug Things that aren't working right in the library. label Aug 25, 2022
@xdev1 xdev1 changed the title Tree component not working properly inside of shadow DOM Tree component not working properly in shadow DOM Aug 25, 2022
@claviska
Copy link
Member

Thanks! Fixed in ca64d26.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Things that aren't working right in the library.
Projects
None yet
Development

No branches or pull requests

2 participants