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' ;
8
2
import { ControlValueAccessor } from '@angular/forms' ;
9
3
import { AutoCompleteConfig } from './auto-complete-config' ;
10
4
import { fadeInOut } from 'ng-devui/utils' ;
@@ -15,10 +9,10 @@ import { CdkOverlayOrigin } from '@angular/cdk/overlay';
15
9
templateUrl : './auto-complete-popup.component.html' ,
16
10
styleUrls : [ 'auto-complete-popup.component.scss' ] ,
17
11
animations : [ fadeInOut ] ,
18
- preserveWhitespaces : false
12
+ preserveWhitespaces : false ,
19
13
} )
20
14
export class AutoCompletePopupComponent implements ControlValueAccessor {
21
- @Input ( ) width ;
15
+ @Input ( ) width : number ;
22
16
@Input ( ) cssClass : string ;
23
17
@Input ( ) maxHeight : number ;
24
18
@Input ( ) disabled : boolean ;
@@ -48,10 +42,7 @@ export class AutoCompletePopupComponent implements ControlValueAccessor {
48
42
private onChange = ( _ : any ) => null ;
49
43
private onTouched = ( ) => null ;
50
44
51
- constructor (
52
- private autoCompleteConfig : AutoCompleteConfig ,
53
- public elementRef : ElementRef
54
- ) {
45
+ constructor ( private autoCompleteConfig : AutoCompleteConfig , public elementRef : ElementRef ) {
55
46
this . formatter = this . autoCompleteConfig . autoComplete . formatter ;
56
47
this . maxHeight = 300 ;
57
48
}
@@ -78,7 +69,8 @@ export class AutoCompletePopupComponent implements ControlValueAccessor {
78
69
event . stopPropagation ( ) ;
79
70
return ;
80
71
}
81
- if ( this . overview === 'single' ) { // 单选场景和单行场景不需要冒泡
72
+ if ( this . overview === 'single' ) {
73
+ // 单选场景和单行场景不需要冒泡
82
74
event . preventDefault ( ) ;
83
75
event . stopPropagation ( ) ;
84
76
}
@@ -102,20 +94,17 @@ export class AutoCompletePopupComponent implements ControlValueAccessor {
102
94
103
95
scrollToActive ( ) : void {
104
96
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 ) ;
117
107
}
118
- } catch ( e ) {
119
108
}
120
109
} ) ;
121
110
}
0 commit comments