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(useActiveElement): support shadow roots #2592

Merged
merged 2 commits into from Jan 3, 2023

Conversation

43081j
Copy link
Contributor

@43081j 43081j commented Dec 28, 2022

Assuming you have a DOM structure like so:

body
  my-element
    #shadow-root
      input

When the input becomes active, the outer document's activeElement will actually be my-element, not the input.

Each shadow root has its own activeElement in case you want to get hold of the inner element in these cases.

This adds support to useActiveElement such that you can pass a shadow root as the document to observe the active element of.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

let me know if there's some reason you wouldn't want this or it needs doing differently and ill update.

dpschen
dpschen previously approved these changes Dec 30, 2022
Assuming you have a DOM structure like so:

```
body
  my-element
    #shadow-root
      input
```

When the `input` becomes active, the outer document's `activeElement`
will actually be `my-element`, _not_ the input.

Each shadow root has its own `activeElement` in case you want to get
hold of the inner element in these cases.

This adds support to `useActiveElement` such that you can pass a shadow
root as the document to observe the active element of.
@43081j
Copy link
Contributor Author

43081j commented Dec 30, 2022

rebased onto master since it was out of date fyi

@antfu antfu changed the title feat (core): support shadow roots in useActiveElement feat(useActiveElement): support shadow roots Jan 3, 2023
@antfu antfu enabled auto-merge (squash) January 3, 2023 13:18
antfu
antfu previously approved these changes Jan 3, 2023
@antfu antfu disabled auto-merge January 3, 2023 13:36
@antfu antfu merged commit 07f2031 into vueuse:main Jan 3, 2023
@43081j 43081j deleted the shady-active-elements branch January 3, 2023 13:50
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