/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { Directive, ElementRef, inject, Input, NgZone, InjectionToken, } from '@angular/core'; import { SharedResizeObserver } from '@angular/cdk/observers/private'; import { Subscription } from 'rxjs'; import * as i0 from "@angular/core"; /** An injion token for the parent form-field. */ export const FLOATING_LABEL_PARENT = new InjectionToken('FloatingLabelParent'); /** * Internal directive that maintains a MDC floating label. This directive does not * use the `MDCFloatingLabelFoundation` class, as it is not worth the size cost of * including it just to measure the label width and toggle some classes. * * The use of a directive allows us to conditionally render a floating label in the * template without having to manually manage instantiation and destruction of the * floating label component based on. * * The component is responsible for setting up the floating label styles, measuring label * width for the outline notch, and providing inputs that can be used to toggle the * label's floating or required state. */ export class MatFormFieldFloatingLabel { /** Whether the label is floating. */ get floating() { return this._floating; } set floating(value) { this._floating = value; if (this.monitorResize) { this._handleResize(); } } /** Whether to monitor for resize events on the floating label. */ get monitorResize() { return this._monitorResize; } set monitorResize(value) { this._monitorResize = value; if (this._monitorResize) { this._subscribeToResize(); } else { this._resizeSubscription.unsubscribe(); } } constructor(_elementRef) { this._elementRef = _elementRef; this._floating = false; this._monitorResize = false; /** The shared ResizeObserver. */ this._resizeObserver = inject(SharedResizeObserver); /** The Angular zone. */ this._ngZone = inject(NgZone); /** The parent form-field. */ this._parent = inject(FLOATING_LABEL_PARENT); /** The current resize event subscription. */ this._resizeSubscription = new Subscription(); } ngOnDestroy() { this._resizeSubscription.unsubscribe(); } /** Gets the width of the label. Used for the outline notch. */ getWidth() { return estimateScrollWidth(this._elementRef.nativeElement); } /** Gets the HTML element for the floating label. */ get element() { return this._elementRef.nativeElement; } /** Handles resize events from the ResizeObserver. */ _handleResize() { // In the case where the label grows in size, the following sequence of events occurs: // 1. The label grows by 1px triggering the ResizeObserver // 2. The notch is expanded to accommodate the entire label // 3. The label expands to its full width, triggering the ResizeObserver again // // This is expected, but If we allow this to all happen within the same macro task it causes an // error: `ResizeObserver loop limit exceeded`. Therefore we push the notch resize out until // the next macro task. setTimeout(() => this._parent._handleLabelResized()); } /** Subscribes to resize events. */ _subscribeToResize() { this._resizeSubscription.unsubscribe(); this._ngZone.runOutsideAngular(() => { this._resizeSubscription = this._resizeObserver .observe(this._elementRef.nativeElement, { box: 'border-box' }) .subscribe(() => this._handleResize()); }); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: MatFormFieldFloatingLabel, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive }); } static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.1.1", type: MatFormFieldFloatingLabel, selector: "label[matFormFieldFloatingLabel]", inputs: { floating: "floating", monitorResize: "monitorResize" }, host: { properties: { "class.mdc-floating-label--float-above": "floating" }, classAttribute: "mdc-floating-label mat-mdc-floating-label" }, ngImport: i0 }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.1", ngImport: i0, type: MatFormFieldFloatingLabel, decorators: [{ type: Directive, args: [{ selector: 'label[matFormFieldFloatingLabel]', host: { 'class': 'mdc-floating-label mat-mdc-floating-label', '[class.mdc-floating-label--float-above]': 'floating', }, }] }], ctorParameters: function () { return [{ type: i0.ElementRef }]; }, propDecorators: { floating: [{ type: Input }], monitorResize: [{ type: Input }] } }); /** * Estimates the scroll width of an element. * via https://github.com/material-components/material-components-web/blob/c0a11ef0d000a098fd0c372be8f12d6a99302855/packages/mdc-dom/ponyfill.ts */ function estimateScrollWidth(element) { // Check the offsetParent. If the element inherits display: none from any // parent, the offsetParent property will be null (see // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/offsetParent). // This check ensures we only clone the node when necessary. const htmlEl = element; if (htmlEl.offsetParent !== null) { return htmlEl.scrollWidth; } const clone = htmlEl.cloneNode(true); clone.style.setProperty('position', 'absolute'); clone.style.setProperty('transform', 'translate(-9999px, -9999px)'); document.documentElement.appendChild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