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

fix(material/form-field): outline label position #29123

Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/material/form-field/form-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Directionality} from '@angular/cdk/bidi';
import {Platform} from '@angular/cdk/platform';
import {Platform, _getShadowRoot} from '@angular/cdk/platform';
import {
AfterContentChecked,
AfterContentInit,
Expand Down Expand Up @@ -703,12 +703,17 @@ export class MatFormField
const element: HTMLElement = this._elementRef.nativeElement;
if (element.getRootNode) {
const rootNode = element.getRootNode();
// If the element is inside the DOM the root node will be either the document
// or the closest shadow root, otherwise it'll be the element itself.
return rootNode && rootNode !== element;
// If the element is inside the DOM the root node will be either the document,
// the closest shadow root or an element that is not yet rendered, otherwise it'll be the element itself.
if (rootNode && rootNode !== element) {
if (rootNode === document || _getShadowRoot(element)) {
return true;
adumitrescu-plenty marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
// Otherwise fall back to checking if it's in the document. This doesn't account for
// shadow DOM, however browser that support shadow DOM should support `getRootNode` as well.
// If the element is not in the document it means that the element is not yet rendered.
return document.documentElement!.contains(element);
adumitrescu-plenty marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading