@@ -12,7 +12,6 @@ import {
12
12
ChangeDetectorRef ,
13
13
Component ,
14
14
ContentChildren ,
15
- Directive ,
16
15
ElementRef ,
17
16
EventEmitter ,
18
17
Inject ,
@@ -33,8 +32,6 @@ import {
33
32
MatOption ,
34
33
mixinDisableRipple ,
35
34
CanDisableRipple ,
36
- _MatOptionBase ,
37
- _MatOptgroupBase ,
38
35
ThemePalette ,
39
36
} from '@angular/material/core' ;
40
37
import { ActiveDescendantKeyManager } from '@angular/cdk/a11y' ;
@@ -53,19 +50,19 @@ let _uniqueAutocompleteIdCounter = 0;
53
50
export class MatAutocompleteSelectedEvent {
54
51
constructor (
55
52
/** Reference to the autocomplete panel that emitted the event. */
56
- public source : _MatAutocompleteBase ,
53
+ public source : MatAutocomplete ,
57
54
/** Option that was selected. */
58
- public option : _MatOptionBase ,
55
+ public option : MatOption ,
59
56
) { }
60
57
}
61
58
62
59
/** Event object that is emitted when an autocomplete option is activated. */
63
60
export interface MatAutocompleteActivatedEvent {
64
61
/** Reference to the autocomplete panel that emitted the event. */
65
- source : _MatAutocompleteBase ;
62
+ source : MatAutocomplete ;
66
63
67
64
/** Option that was selected. */
68
- option : _MatOptionBase | null ;
65
+ option : MatOption | null ;
69
66
}
70
67
71
68
// Boilerplate for applying mixins to MatAutocomplete.
@@ -112,25 +109,39 @@ export function MAT_AUTOCOMPLETE_DEFAULT_OPTIONS_FACTORY(): MatAutocompleteDefau
112
109
} ;
113
110
}
114
111
115
- /** Base class with all of the `MatAutocomplete` functionality. */
116
- @Directive ( )
117
- export abstract class _MatAutocompleteBase
112
+ /** Autocomplete component. */
113
+ @Component ( {
114
+ selector : 'mat-autocomplete' ,
115
+ templateUrl : 'autocomplete.html' ,
116
+ styleUrls : [ 'autocomplete.css' ] ,
117
+ encapsulation : ViewEncapsulation . None ,
118
+ changeDetection : ChangeDetectionStrategy . OnPush ,
119
+ exportAs : 'matAutocomplete' ,
120
+ inputs : [ 'disableRipple' ] ,
121
+ host : {
122
+ 'class' : 'mat-mdc-autocomplete' ,
123
+ 'ngSkipHydration' : '' ,
124
+ } ,
125
+ providers : [ { provide : MAT_OPTION_PARENT_COMPONENT , useExisting : MatAutocomplete } ] ,
126
+ animations : [ panelAnimation ] ,
127
+ } )
128
+ export class MatAutocomplete
118
129
extends _MatAutocompleteMixinBase
119
130
implements AfterContentInit , CanDisableRipple , OnDestroy
120
131
{
121
132
private _activeOptionChanges = Subscription . EMPTY ;
122
133
123
134
/** Class to apply to the panel when it's visible. */
124
- protected abstract _visibleClass : string ;
135
+ private _visibleClass = 'mat-mdc-autocomplete-visible' ;
125
136
126
137
/** Class to apply to the panel when it's hidden. */
127
- protected abstract _hiddenClass : string ;
138
+ private _hiddenClass = 'mat-mdc-autocomplete-hidden' ;
128
139
129
140
/** Emits when the panel animation is done. Null if the panel doesn't animate. */
130
- abstract _animationDone : EventEmitter < AnimationEvent > | null ;
141
+ _animationDone = new EventEmitter < AnimationEvent > ( ) ;
131
142
132
143
/** Manages active item in option list based on key events. */
133
- _keyManager : ActiveDescendantKeyManager < _MatOptionBase > ;
144
+ _keyManager : ActiveDescendantKeyManager < MatOption > ;
134
145
135
146
/** Whether the autocomplete panel should be visible, depending on option length. */
136
147
showPanel : boolean = false ;
@@ -160,10 +171,10 @@ export abstract class _MatAutocompleteBase
160
171
@ViewChild ( 'panel' ) panel : ElementRef ;
161
172
162
173
/** Reference to all options within the autocomplete. */
163
- abstract options : QueryList < _MatOptionBase > ;
174
+ @ ContentChildren ( MatOption , { descendants : true } ) options : QueryList < MatOption > ;
164
175
165
176
/** Reference to all option groups within the autocomplete. */
166
- abstract optionGroups : QueryList < _MatOptgroupBase > ;
177
+ @ ContentChildren ( MAT_OPTGROUP , { descendants : true } ) optionGroups : QueryList < MatOptgroup > ;
167
178
168
179
/** Aria label of the autocomplete. */
169
180
@Input ( 'aria-label' ) ariaLabel : string ;
@@ -253,6 +264,27 @@ export abstract class _MatAutocompleteBase
253
264
}
254
265
_classList : { [ key : string ] : boolean } = { } ;
255
266
267
+ /** Whether checkmark indicator for single-selection options is hidden. */
268
+ @Input ( )
269
+ get hideSingleSelectionIndicator ( ) : boolean {
270
+ return this . _hideSingleSelectionIndicator ;
271
+ }
272
+ set hideSingleSelectionIndicator ( value : BooleanInput ) {
273
+ this . _hideSingleSelectionIndicator = coerceBooleanProperty ( value ) ;
274
+ this . _syncParentProperties ( ) ;
275
+ }
276
+ private _hideSingleSelectionIndicator : boolean =
277
+ this . _defaults . hideSingleSelectionIndicator ?? false ;
278
+
279
+ /** Syncs the parent state with the individual options. */
280
+ _syncParentProperties ( ) : void {
281
+ if ( this . options ) {
282
+ for ( const option of this . options ) {
283
+ option . _changeDetectorRef . markForCheck ( ) ;
284
+ }
285
+ }
286
+ }
287
+
256
288
/** Unique ID to be used by autocomplete trigger's "aria-owns" property. */
257
289
id : string = `mat-autocomplete-${ _uniqueAutocompleteIdCounter ++ } ` ;
258
290
@@ -281,7 +313,7 @@ export abstract class _MatAutocompleteBase
281
313
}
282
314
283
315
ngAfterContentInit ( ) {
284
- this . _keyManager = new ActiveDescendantKeyManager < _MatOptionBase > ( this . options )
316
+ this . _keyManager = new ActiveDescendantKeyManager < MatOption > ( this . options )
285
317
. withWrap ( )
286
318
. skipPredicate ( this . _skipPredicate ) ;
287
319
this . _activeOptionChanges = this . _keyManager . change . subscribe ( index => {
@@ -297,6 +329,7 @@ export abstract class _MatAutocompleteBase
297
329
ngOnDestroy ( ) {
298
330
this . _keyManager ?. destroy ( ) ;
299
331
this . _activeOptionChanges . unsubscribe ( ) ;
332
+ this . _animationDone . complete ( ) ;
300
333
}
301
334
302
335
/**
@@ -322,7 +355,7 @@ export abstract class _MatAutocompleteBase
322
355
}
323
356
324
357
/** Emits the `select` event. */
325
- _emitSelectEvent ( option : _MatOptionBase ) : void {
358
+ _emitSelectEvent ( option : MatOption ) : void {
326
359
const event = new MatAutocompleteSelectedEvent ( this , option ) ;
327
360
this . optionSelected . emit ( event ) ;
328
361
}
@@ -350,61 +383,6 @@ export abstract class _MatAutocompleteBase
350
383
classList [ 'mat-accent' ] = this . _color === 'accent' ;
351
384
}
352
385
353
- protected _skipPredicate ( option : _MatOptionBase ) {
354
- return option . disabled ;
355
- }
356
- }
357
-
358
- @Component ( {
359
- selector : 'mat-autocomplete' ,
360
- templateUrl : 'autocomplete.html' ,
361
- styleUrls : [ 'autocomplete.css' ] ,
362
- encapsulation : ViewEncapsulation . None ,
363
- changeDetection : ChangeDetectionStrategy . OnPush ,
364
- exportAs : 'matAutocomplete' ,
365
- inputs : [ 'disableRipple' ] ,
366
- host : {
367
- 'class' : 'mat-mdc-autocomplete' ,
368
- 'ngSkipHydration' : '' ,
369
- } ,
370
- providers : [ { provide : MAT_OPTION_PARENT_COMPONENT , useExisting : MatAutocomplete } ] ,
371
- animations : [ panelAnimation ] ,
372
- } )
373
- export class MatAutocomplete extends _MatAutocompleteBase implements OnDestroy {
374
- /** Reference to all option groups within the autocomplete. */
375
- @ContentChildren ( MAT_OPTGROUP , { descendants : true } ) optionGroups : QueryList < MatOptgroup > ;
376
- /** Reference to all options within the autocomplete. */
377
- @ContentChildren ( MatOption , { descendants : true } ) options : QueryList < MatOption > ;
378
- protected _visibleClass = 'mat-mdc-autocomplete-visible' ;
379
- protected _hiddenClass = 'mat-mdc-autocomplete-hidden' ;
380
- override _animationDone = new EventEmitter < AnimationEvent > ( ) ;
381
-
382
- /** Whether checkmark indicator for single-selection options is hidden. */
383
- @Input ( )
384
- get hideSingleSelectionIndicator ( ) : boolean {
385
- return this . _hideSingleSelectionIndicator ;
386
- }
387
- set hideSingleSelectionIndicator ( value : BooleanInput ) {
388
- this . _hideSingleSelectionIndicator = coerceBooleanProperty ( value ) ;
389
- this . _syncParentProperties ( ) ;
390
- }
391
- private _hideSingleSelectionIndicator : boolean =
392
- this . _defaults . hideSingleSelectionIndicator ?? false ;
393
-
394
- /** Syncs the parent state with the individual options. */
395
- _syncParentProperties ( ) : void {
396
- if ( this . options ) {
397
- for ( const option of this . options ) {
398
- option . _changeDetectorRef . markForCheck ( ) ;
399
- }
400
- }
401
- }
402
-
403
- override ngOnDestroy ( ) : void {
404
- super . ngOnDestroy ( ) ;
405
- this . _animationDone . complete ( ) ;
406
- }
407
-
408
386
// `skipPredicate` determines if key manager should avoid putting a given option in the tab
409
387
// order. Allow disabled list items to receive focus via keyboard to align with WAI ARIA
410
388
// recommendation.
@@ -419,7 +397,7 @@ export class MatAutocomplete extends _MatAutocompleteBase implements OnDestroy {
419
397
//
420
398
// The user can focus disabled options using the keyboard, but the user cannot click disabled
421
399
// options.
422
- protected override _skipPredicate ( _option : _MatOptionBase ) {
400
+ protected _skipPredicate ( ) {
423
401
return false ;
424
402
}
425
403
}
0 commit comments