1- import {
2- Component ,
3- ElementRef ,
4- Input ,
5- TemplateRef ,
6- ViewChild
7- } from '@angular/core' ;
1+ import { Component , ElementRef , Input , TemplateRef , ViewChild } from '@angular/core' ;
82import { ControlValueAccessor } from '@angular/forms' ;
93import { AutoCompleteConfig } from './auto-complete-config' ;
104import { fadeInOut } from 'ng-devui/utils' ;
@@ -15,10 +9,10 @@ import { CdkOverlayOrigin } from '@angular/cdk/overlay';
159 templateUrl : './auto-complete-popup.component.html' ,
1610 styleUrls : [ 'auto-complete-popup.component.scss' ] ,
1711 animations : [ fadeInOut ] ,
18- preserveWhitespaces : false
12+ preserveWhitespaces : false ,
1913} )
2014export class AutoCompletePopupComponent implements ControlValueAccessor {
21- @Input ( ) width ;
15+ @Input ( ) width : number ;
2216 @Input ( ) cssClass : string ;
2317 @Input ( ) maxHeight : number ;
2418 @Input ( ) disabled : boolean ;
@@ -48,10 +42,7 @@ export class AutoCompletePopupComponent implements ControlValueAccessor {
4842 private onChange = ( _ : any ) => null ;
4943 private onTouched = ( ) => null ;
5044
51- constructor (
52- private autoCompleteConfig : AutoCompleteConfig ,
53- public elementRef : ElementRef
54- ) {
45+ constructor ( private autoCompleteConfig : AutoCompleteConfig , public elementRef : ElementRef ) {
5546 this . formatter = this . autoCompleteConfig . autoComplete . formatter ;
5647 this . maxHeight = 300 ;
5748 }
@@ -78,7 +69,8 @@ export class AutoCompletePopupComponent implements ControlValueAccessor {
7869 event . stopPropagation ( ) ;
7970 return ;
8071 }
81- if ( this . overview === 'single' ) { // 单选场景和单行场景不需要冒泡
72+ if ( this . overview === 'single' ) {
73+ // 单选场景和单行场景不需要冒泡
8274 event . preventDefault ( ) ;
8375 event . stopPropagation ( ) ;
8476 }
@@ -102,20 +94,17 @@ export class AutoCompletePopupComponent implements ControlValueAccessor {
10294
10395 scrollToActive ( ) : void {
10496 const that = this ;
105- setTimeout ( _ => {
106- try {
107- const selectIndex = that . activeIndex ;
108- const scrollPane : any = that . dropdownUl . nativeElement . children [ selectIndex ] ;
109- if ( scrollPane . scrollIntoViewIfNeeded ) {
110- scrollPane . scrollIntoViewIfNeeded ( false ) ;
111- } else {
112- const containerInfo = that . dropdownUl . nativeElement . getBoundingClientRect ( ) ;
113- const elementInfo = scrollPane . getBoundingClientRect ( ) ;
114- if ( elementInfo . bottom > containerInfo . bottom || elementInfo . top < containerInfo . top ) {
115- scrollPane . scrollIntoView ( false ) ;
116- }
97+ setTimeout ( ( ) => {
98+ const selectIndex = that . activeIndex ;
99+ const scrollPane : any = that . dropdownUl . nativeElement . children [ selectIndex ] ;
100+ if ( scrollPane . scrollIntoViewIfNeeded ) {
101+ scrollPane . scrollIntoViewIfNeeded ( false ) ;
102+ } else {
103+ const containerInfo = that . dropdownUl . nativeElement . getBoundingClientRect ( ) ;
104+ const elementInfo = scrollPane . getBoundingClientRect ( ) ;
105+ if ( elementInfo . bottom > containerInfo . bottom || elementInfo . top < containerInfo . top ) {
106+ scrollPane . scrollIntoView ( false ) ;
117107 }
118- } catch ( e ) {
119108 }
120109 } ) ;
121110 }
0 commit comments