fix(VTextField): detect activeElement from shadowRoot #13053
Merged
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.
Description
When an input element is inside a shadowDom, and is active (focused), the
document.activeElement
will not reference the input element but rather its shadowRoot. In order to properly detect what theactiveElement
is, we must use the proper root node for that element, as explained on MDN.This PR:
tryAutofocus
, and during the processing ofonFocus
event.focus
/activeElement
dependent tests to attach the mounted components to the DOM (read below for motivation)Motivation and Context
This is part of the solution for #7622 ("Weird behaviour inside shadow DOM"). If fixes focus related issues when using Vuetify inside a shadow DOM.
It also improves the code base by attaching the element to the DOM for tests related to focus. This is important because Browsers (as well as
jsdom
used in tests) have a different behavior when trying to focus an element that is attached, and not (namely, when you focus an element that is not attached, is will not become thedocumet.activeElement
).How Has This Been Tested?
unit
Markup:
Types of changes
Checklist:
master
for bug fixes and documentation updates,dev
for new features and backwards compatible changes andnext
for non-backwards compatible changes).