-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix focus not returned to SVG Element #3704
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
0ac2d9e
to
85f288d
Compare
This was also causing visual issues in my editor, so fixed it while I was at it.
This also adds a new `isElement` which is more specific than a Node, but less specific than an HTMLElement. E.g.: an `SVG` is an `Element` but not an `HTMLElement` - For `isNode` we just check for `nodeType` - For `isElement` we check that it's a `Node`, and has a `tagName` (which is the same as the `nodeName` but only available in `Element`s) - For `isHTMLElement` we check that it's an `Element`, and has an `accessKey` which is only available in `HTMLElement`s but not in `Element`.
Otherwise `SVG`s won't be focusable even if they are focusable because they don't inherit from `HTMLElement`
`HTMLOrSVGElement` doesn't inherit from anything, so we union it with `Element` to make future types happy.
For the `d.style(…)` function, we expect a node that has a `style` attribute. We don't care what kind of node that it is.
We only require `.matches(…)` which is available on `Element` so no need for `HTMLElement`
85f288d
to
475af9c
Compare
This was referenced Apr 25, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue where the focus is not returned to an
SVG
element with atabIndex
correctly.There are a few issues going on here:
e.target
) is an instanceofHTMLElement
, but theSVGElement
is not an instanceofHTMLElement
.instanceof
we are checking against concrete classes, so if this happen to cross certain contexts (Shadow DOM, Iframes, ...) then the instances would be different.To solve this, we will now:
HTMLElement
toElement
for example.Fixes: #3660
Test plan
Added an SVG to open a Dialog component and made sure that pressing
escape
or clicking outside of the Dialog does restore the focus to the SVG itself.Here is a video of that behavior:
Screen.Recording.2025-04-25.at.12.00.45.mov