From 2fbe7f1933f4bd5de96e6428234e56965616120e Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 15 Nov 2018 09:24:56 +0100 Subject: Fix new Angular 7 issues --- .../shared/forms/textarea-autoresize.directive.ts | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 client/src/app/shared/forms/textarea-autoresize.directive.ts (limited to 'client/src/app/shared/forms/textarea-autoresize.directive.ts') diff --git a/client/src/app/shared/forms/textarea-autoresize.directive.ts b/client/src/app/shared/forms/textarea-autoresize.directive.ts new file mode 100644 index 000000000..f8c855c16 --- /dev/null +++ b/client/src/app/shared/forms/textarea-autoresize.directive.ts @@ -0,0 +1,25 @@ +// Thanks: https://github.com/evseevdev/ngx-textarea-autosize +import { AfterViewInit, Directive, ElementRef, HostBinding, HostListener } from '@angular/core' + +@Directive({ + selector: 'textarea[myAutoResize]' +}) +export class TextareaAutoResizeDirective implements AfterViewInit { + @HostBinding('attr.rows') rows = '1' + @HostBinding('style.overflow') overflow = 'hidden' + + constructor (private elem: ElementRef) { } + + public ngAfterViewInit () { + this.resize() + } + + @HostListener('input') + resize () { + const textarea = this.elem.nativeElement as HTMLTextAreaElement + // Reset textarea height to auto that correctly calculate the new height + textarea.style.height = 'auto' + // Set new height + textarea.style.height = `${textarea.scrollHeight}px` + } +} -- cgit v1.2.3