Skip to content

Commit

Permalink
fix(material/form-field): outline label position (#29123)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
adumitrescu-plenty authored May 28, 2024
1 parent f5f61fa commit eb22e2e
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 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 @@ -701,14 +701,13 @@ export class MatFormField
/** Checks whether the form field is attached to the DOM. */
private _isAttachedToDom(): boolean {
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;
}
// 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);
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))
);
}
}

0 comments on commit eb22e2e

Please sign in to comment.