111 lines
3.5 KiB
JavaScript
111 lines
3.5 KiB
JavaScript
import { EventEmitter, Directive, ElementRef, Optional, Input, Output, HostListener, NgModule } from '@angular/core';
|
|
import { NgModel, NgControl } from '@angular/forms';
|
|
import { CommonModule } from '@angular/common';
|
|
|
|
class InputTextarea {
|
|
constructor(el, ngModel, control) {
|
|
this.el = el;
|
|
this.ngModel = ngModel;
|
|
this.control = control;
|
|
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();
|
|
}
|
|
onInput(e) {
|
|
this.updateState();
|
|
}
|
|
updateFilledState() {
|
|
this.filled = (this.el.nativeElement.value && this.el.nativeElement.value.length) || (this.ngModel && this.ngModel.model);
|
|
}
|
|
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 }] }
|
|
];
|
|
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
|