angular-auto-size-input
Version:
Plug and Play directive to automatically scale textareas to their contents. Works while yout type, copy, cut, and paste.
74 lines (69 loc) • 2.44 kB
JavaScript
import { Directive, ElementRef, HostBinding, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var AutoSizeInputDirective = (function () {
function AutoSizeInputDirective(_elementRef) {
var _this = this;
this._elementRef = _elementRef;
this.resize = function () {
_this._elementRef.nativeElement.style.height = 'auto';
_this._elementRef.nativeElement.style.height = _this._elementRef.nativeElement.scrollHeight + 'px';
};
this.delayedResize = function () {
setTimeout(_this.resize, 0);
};
}
/**
* @return {?}
*/
AutoSizeInputDirective.prototype.ngAfterViewInit = /**
* @return {?}
*/
function () {
this._elementRef.nativeElement.addEventListener('change', this.resize);
this._elementRef.nativeElement.addEventListener('cut', this.delayedResize);
this._elementRef.nativeElement.addEventListener('paste', this.delayedResize);
this._elementRef.nativeElement.addEventListener('drop', this.delayedResize);
this._elementRef.nativeElement.addEventListener('keydown', this.delayedResize);
this.delayedResize();
};
AutoSizeInputDirective.decorators = [
{ type: Directive, args: [{
selector: 'textarea[asAutoSizeInput]'
},] },
];
/** @nocollapse */
AutoSizeInputDirective.ctorParameters = function () { return [
{ type: ElementRef, },
]; };
AutoSizeInputDirective.propDecorators = {
"true": [{ type: HostBinding, args: ['class.as-auto-size-input',] },],
};
return AutoSizeInputDirective;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var AutoSizeInputModule = (function () {
function AutoSizeInputModule() {
}
AutoSizeInputModule.decorators = [
{ type: NgModule, args: [{
declarations: [AutoSizeInputDirective],
exports: [AutoSizeInputDirective],
imports: [CommonModule]
},] },
];
/** @nocollapse */
AutoSizeInputModule.ctorParameters = function () { return []; };
return AutoSizeInputModule;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
export { AutoSizeInputModule };