import { Component, Input, ViewChild, ElementRef, AfterViewInit } from '@angular/core'; @Component({ selector: 'bom-add-part-modal', templateUrl: 'add-part-modal.component.html', styleUrls: ['./add-part-modal.component.scss'] }) export class AddPartModalComponent implements AfterViewInit { @ViewChild('partNumberTextArea', { static: true }) partNumberTextArea: ElementRef; @Input() content: string; data: { invalid: boolean; partNumbers: string } = { invalid: true, partNumbers: '' }; constructor() {} ngAfterViewInit(): void { // Setting focus on an element in this modal causes the // scroll bar to go to the bottom of the BOM (noticeable // when there are ≈10 or more rows on the page) const scrollPos = document.documentElement.scrollTop; this.partNumberTextArea.nativeElement.focus(); window.scrollTo(0, scrollPos); } /** * Listens for ngModel changes * @param partsString */ onChange(partsString: any, data): void { partsString = partsString.trim(); data.partNumbers = partsString; partsString ? (data.invalid = false) : (data.invalid = true); } }