From 3d13876dfce43f85ac28e6fc39d4835abc623244 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Wed, 29 May 2024 11:30:03 +0200 Subject: [PATCH] Revert "fix(material/form-field): outline label position (#29123)" (#29132) This reverts commit eb22e2e85fc007c6357067a2fcf57cb54283f8d5. (cherry picked from commit 0106420dc1952dffc30dbcc6d89ca41ba92c0ce7) --- src/material/form-field/form-field.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/material/form-field/form-field.ts b/src/material/form-field/form-field.ts index ca68a26f677a..0b6e02e40164 100644 --- a/src/material/form-field/form-field.ts +++ b/src/material/form-field/form-field.ts @@ -6,7 +6,7 @@ * found in the LICENSE file at https://angular.io/license */ import {Directionality} from '@angular/cdk/bidi'; -import {Platform, _getShadowRoot} from '@angular/cdk/platform'; +import {Platform} from '@angular/cdk/platform'; import { AfterContentChecked, AfterContentInit, @@ -701,13 +701,14 @@ export class MatFormField /** Checks whether the form field is attached to the DOM. */ private _isAttachedToDom(): boolean { const element: HTMLElement = this._elementRef.nativeElement; - const rootNode = element.getRootNode(); - // 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. - return ( - rootNode && - rootNode !== element && - (rootNode === document || rootNode === _getShadowRoot(element)) - ); + 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; + } + // 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. + return document.documentElement!.contains(element); } }