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

feat(keyboard): support shadow DOM in tab order #1040

Open
wants to merge 38 commits into
base: main
Choose a base branch
from

Conversation

ph-fritsche
Copy link
Member

What:

Consider focusable elements in shadow trees.

Why:
#1026

Checklist:

  • Tests
  • Ready to be merged

on top of #1038 -- should be rebased once that is merged

Christian24 and others added 30 commits August 7, 2022 17:34
Co-authored-by: Philipp Fritsche <ph.fritsche@gmail.com>
…DOM in setup(). Removed old custom elements test
Co-authored-by: Philipp Fritsche <ph.fritsche@gmail.com>
Co-authored-by: Philipp Fritsche <ph.fritsche@gmail.com>
Co-authored-by: Philipp Fritsche <ph.fritsche@gmail.com>
@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 7756374:

Sandbox Source
userEvent-dom Configuration
userEvent-react Configuration

@ph-fritsche
Copy link
Member Author

@codecov
Copy link

codecov bot commented Aug 19, 2022

Codecov Report

Merging #1040 (7756374) into main (1aa2027) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main     #1040   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           88        87    -1     
  Lines         2061      2099   +38     
  Branches       691       713   +22     
=========================================
+ Hits          2061      2099   +38     
Impacted Files Coverage Δ
src/clipboard/copy.ts 100.00% <100.00%> (ø)
src/clipboard/cut.ts 100.00% <100.00%> (ø)
src/clipboard/paste.ts 100.00% <100.00%> (ø)
src/event/behavior/click.ts 100.00% <100.00%> (ø)
src/event/behavior/keydown.ts 100.00% <100.00%> (ø)
src/event/focus.ts 100.00% <100.00%> (ø)
src/event/selection/updateSelectionOnFocus.ts 100.00% <100.00%> (ø)
src/utils/focus/focusable.ts 100.00% <100.00%> (ø)
src/utils/focus/getActiveElement.ts 100.00% <100.00%> (ø)
src/utils/focus/getTabDestination.ts 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@ph-fritsche
Copy link
Member Author

@Christian24 This should complete support for focus handling on shadow DOM

@Christian24
Copy link

Thanks @ph-fritsche! Really looking forward to seeing this in the next release.

Copy link

@Christian24 Christian24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking what I could do to help this along, so here is some very minor feedback @ph-fritsche :)

* as it might delegate focus into a shadow tree.
*/
export function isFocusTarget(element: Element): element is HTMLElement {
if (element.tagName.includes('-')) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dunno but I think having this a separate helper function might be helpful. And makes it more clear as well.


export function isFocusable(element: Element): element is HTMLElement {
return (
!element.tagName.includes('-') &&

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

// see https://github.com/jsdom/jsdom/issues/3418
// We'll treat `undefined` as `true`
return (
!!element.shadowRoot &&

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't element.shadowRoot be sufficient here? The !! shouldn't make a difference right?

if (isFocusable(el)) {
return el
} else if (el.shadowRoot) {
const f = findFocusable(el.shadowRoot)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a more describing name than f. Maybe focusable or focusableEl?

@ysgit
Copy link

ysgit commented Nov 8, 2023

@ph-fritsche @Christian24 is there anything that can be done to get this, #1038 and #1033 back on the table? I would be glad to help or find someone from my team who can.

@Christian24
Copy link

I would love to get this merged. I think @ph-fritsche wanted to finish work on #1019 first though. I could potentially use this for something else I have been working on myself too. I am not a maintainer here though, so I cannot really comment on their goals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants