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

Add a note about how delegatesFocus about focusable element placement #37101

Merged
merged 2 commits into from
Dec 5, 2024

Conversation

KonnorRogers
Copy link
Contributor

Description

I was testing around with delegatesFocus and it seems that it will only delegate focus to elements that live inside the shadow dom.

If you have focusable elements in the light dom, they will not get focused.

Example:

https://codepen.io/paramagicdev/pen/ByBjogK?editors=1010

<my-element>
  <template shadowrootmode="open" shadowrootdelegatesfocus="true">
    <slot></slot>
  </template>
  <button>Hello World</button>
</my-element>

Call .focus() on <my-element> will not shift focus.

However, if you embedded the "focusable part" inside the shadow dom, delegatesFocus will work as expected.

<my-element>
  <template shadowrootmode="open" shadowrootdelegatesfocus="true">
      <button>Hello World</button>
  </template>
  </my-element>

Motivation

delegatesFocus not working for light dom elements was perplexing me.

Additional details

Related issues and pull requests

I was testing around with `delegatesFocus` and it seems that it will only delegate focus to elements that live inside the shadow dom.

If you have focusable elements in the light dom, they will not get focused.

Example:

https://codepen.io/paramagicdev/pen/ByBjogK?editors=1010

```html
<my-element>
  <template shadowrootmode="open" shadowrootdelegatesfocus="true">
    <slot></slot>
  </template>
  <button>Hello World</button>
</my-element>
```

Call `.focus()` on `<my-element>` *will not* shift focus.

However, if you embedded the "focusable part" inside the shadow dom, delegatesFocus will work as expected.

```html
<my-element>
  <template shadowrootmode="open" shadowrootdelegatesfocus="true">
      <button>Hello World</button>
  </template>
  </my-element>
```
@KonnorRogers KonnorRogers requested a review from a team as a code owner December 5, 2024 00:32
@KonnorRogers KonnorRogers requested review from wbamberg and removed request for a team December 5, 2024 00:32
@github-actions github-actions bot added Content:WebAPI Web API docs size/xs [PR only] 0-5 LoC changed labels Dec 5, 2024
Copy link
Contributor

github-actions bot commented Dec 5, 2024

Preview URLs

(comment last updated: 2024-12-05 01:27:54)

Copy link
Collaborator

@wbamberg wbamberg left a comment

Choose a reason for hiding this comment

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

👍 thank you @KonnorRogers !

@wbamberg wbamberg merged commit 04f1321 into mdn:main Dec 5, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:WebAPI Web API docs size/xs [PR only] 0-5 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants