UNPKG

primeng

Version:

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![npm version](https://badge.fury.io/js/primeng.svg)](https://badge.fury.io/js/primeng) [![npm downloads](https://img.shields.io/npm/dm/primeng.sv

115 lines (111 loc) 3.64 kB
import { EventEmitter, Directive, ElementRef, Optional, ChangeDetectorRef, Input, Output, HostListener, NgModule } from '@angular/core'; import { NgModel, NgControl } from '@angular/forms'; import { CommonModule } from '@angular/common'; class InputTextarea { constructor(el, ngModel, control, cd) { this.el = el; this.ngModel = ngModel; this.control = control; this.cd = cd; this.onResize = new EventEmitter(); } ngOnInit() { if (this.ngModel) { this.ngModelSubscription = this.ngModel.valueChanges.subscribe(() => { this.updateState(); }); } if (this.control) { this.ngControlSubscription = this.control.valueChanges.subscribe(() => { this.updateState(); }); } } ngAfterViewInit() { if (this.autoResize) this.resize(); this.updateFilledState(); this.cd.detectChanges(); } onInput(e) { this.updateState(); } updateFilledState() { this.filled = this.el.nativeElement.value && this.el.nativeElement.value.length; } onFocus(e) { if (this.autoResize) { this.resize(e); } } onBlur(e) { if (this.autoResize) { this.resize(e); } } resize(event) { this.el.nativeElement.style.height = 'auto'; this.el.nativeElement.style.height = this.el.nativeElement.scrollHeight + 'px'; if (parseFloat(this.el.nativeElement.style.height) >= parseFloat(this.el.nativeElement.style.maxHeight)) { this.el.nativeElement.style.overflowY = "scroll"; this.el.nativeElement.style.height = this.el.nativeElement.style.maxHeight; } else { this.el.nativeElement.style.overflow = "hidden"; } this.onResize.emit(event || {}); } updateState() { this.updateFilledState(); if (this.autoResize) { this.resize(); } } ngOnDestroy() { if (this.ngModelSubscription) { this.ngModelSubscription.unsubscribe(); } if (this.ngControlSubscription) { this.ngControlSubscription.unsubscribe(); } } } InputTextarea.decorators = [ { type: Directive, args: [{ selector: '[pInputTextarea]', host: { '[class.p-inputtextarea]': 'true', '[class.p-inputtext]': 'true', '[class.p-component]': 'true', '[class.p-filled]': 'filled', '[class.p-inputtextarea-resizable]': 'autoResize' } },] } ]; InputTextarea.ctorParameters = () => [ { type: ElementRef }, { type: NgModel, decorators: [{ type: Optional }] }, { type: NgControl, decorators: [{ type: Optional }] }, { type: ChangeDetectorRef } ]; InputTextarea.propDecorators = { autoResize: [{ type: Input }], onResize: [{ type: Output }], onInput: [{ type: HostListener, args: ['input', ['$event'],] }], onFocus: [{ type: HostListener, args: ['focus', ['$event'],] }], onBlur: [{ type: HostListener, args: ['blur', ['$event'],] }] }; class InputTextareaModule { } InputTextareaModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule], exports: [InputTextarea], declarations: [InputTextarea] },] } ]; /** * Generated bundle index. Do not edit. */ export { InputTextarea, InputTextareaModule }; //# sourceMappingURL=primeng-inputtextarea.js.map