Skip to content

Commit b7c0a6e

Browse files
adumitrescu-plentycrisbeto
authored andcommitted
fix(material/form-field): outline label position (#29123)
* fix(form-field): outline label position Fixes the outline label position when a prefix is present and the form field is not yet rendered. Fixes #29064 * fix(material/form-field): adjust text * fix(material/form-field): requested changes * fix(material/form-field): adjustments for shadow root * fix(material/form-field): adjust shadow node check * fix(material/form-field): adjust logic Simplify the method (cherry picked from commit eb22e2e)
1 parent af6bbf5 commit b7c0a6e

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/material/form-field/form-field.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import {Directionality} from '@angular/cdk/bidi';
9-
import {Platform} from '@angular/cdk/platform';
9+
import {Platform, _getShadowRoot} from '@angular/cdk/platform';
1010
import {
1111
AfterContentChecked,
1212
AfterContentInit,
@@ -701,14 +701,13 @@ export class MatFormField
701701
/** Checks whether the form field is attached to the DOM. */
702702
private _isAttachedToDom(): boolean {
703703
const element: HTMLElement = this._elementRef.nativeElement;
704-
if (element.getRootNode) {
705-
const rootNode = element.getRootNode();
706-
// If the element is inside the DOM the root node will be either the document
707-
// or the closest shadow root, otherwise it'll be the element itself.
708-
return rootNode && rootNode !== element;
709-
}
710-
// Otherwise fall back to checking if it's in the document. This doesn't account for
711-
// shadow DOM, however browser that support shadow DOM should support `getRootNode` as well.
712-
return document.documentElement!.contains(element);
704+
const rootNode = element.getRootNode();
705+
// If the element is inside the DOM the root node will be either the document,
706+
// the closest shadow root or an element that is not yet rendered, otherwise it'll be the element itself.
707+
return (
708+
rootNode &&
709+
rootNode !== element &&
710+
(rootNode === document || rootNode === _getShadowRoot(element))
711+
);
713712
}
714713
}

0 commit comments

Comments
 (0)