@@ -23,19 +23,18 @@ import {
23
23
TemplateRef ,
24
24
ViewChild ,
25
25
ViewEncapsulation ,
26
+ booleanAttribute ,
26
27
} from '@angular/core' ;
27
28
import { AnimationEvent } from '@angular/animations' ;
28
29
import {
29
30
MAT_OPTGROUP ,
30
31
MAT_OPTION_PARENT_COMPONENT ,
31
32
MatOptgroup ,
32
33
MatOption ,
33
- mixinDisableRipple ,
34
- CanDisableRipple ,
35
34
ThemePalette ,
36
35
} from '@angular/material/core' ;
37
36
import { ActiveDescendantKeyManager } from '@angular/cdk/a11y' ;
38
- import { BooleanInput , coerceBooleanProperty , coerceStringArray } from '@angular/cdk/coercion' ;
37
+ import { coerceStringArray } from '@angular/cdk/coercion' ;
39
38
import { Platform } from '@angular/cdk/platform' ;
40
39
import { panelAnimation } from './animations' ;
41
40
import { Subscription } from 'rxjs' ;
@@ -65,10 +64,6 @@ export interface MatAutocompleteActivatedEvent {
65
64
option : MatOption | null ;
66
65
}
67
66
68
- // Boilerplate for applying mixins to MatAutocomplete.
69
- /** @docs -private */
70
- const _MatAutocompleteMixinBase = mixinDisableRipple ( class { } ) ;
71
-
72
67
/** Default `mat-autocomplete` options that can be overridden. */
73
68
export interface MatAutocompleteDefaultOptions {
74
69
/** Whether the first option should be highlighted when an autocomplete panel is opened. */
@@ -117,18 +112,14 @@ export function MAT_AUTOCOMPLETE_DEFAULT_OPTIONS_FACTORY(): MatAutocompleteDefau
117
112
encapsulation : ViewEncapsulation . None ,
118
113
changeDetection : ChangeDetectionStrategy . OnPush ,
119
114
exportAs : 'matAutocomplete' ,
120
- inputs : [ 'disableRipple' ] ,
121
115
host : {
122
116
'class' : 'mat-mdc-autocomplete' ,
123
117
'ngSkipHydration' : '' ,
124
118
} ,
125
119
providers : [ { provide : MAT_OPTION_PARENT_COMPONENT , useExisting : MatAutocomplete } ] ,
126
120
animations : [ panelAnimation ] ,
127
121
} )
128
- export class MatAutocomplete
129
- extends _MatAutocompleteMixinBase
130
- implements AfterContentInit , CanDisableRipple , OnDestroy
131
- {
122
+ export class MatAutocomplete implements AfterContentInit , OnDestroy {
132
123
private _activeOptionChanges = Subscription . EMPTY ;
133
124
134
125
/** Class to apply to the panel when it's visible. */
@@ -189,46 +180,28 @@ export class MatAutocomplete
189
180
* Whether the first option should be highlighted when the autocomplete panel is opened.
190
181
* Can be configured globally through the `MAT_AUTOCOMPLETE_DEFAULT_OPTIONS` token.
191
182
*/
192
- @Input ( )
193
- get autoActiveFirstOption ( ) : boolean {
194
- return this . _autoActiveFirstOption ;
195
- }
196
- set autoActiveFirstOption ( value : BooleanInput ) {
197
- this . _autoActiveFirstOption = coerceBooleanProperty ( value ) ;
198
- }
199
- private _autoActiveFirstOption : boolean ;
183
+ @Input ( { transform : booleanAttribute } ) autoActiveFirstOption : boolean ;
200
184
201
185
/** Whether the active option should be selected as the user is navigating. */
202
- @Input ( )
203
- get autoSelectActiveOption ( ) : boolean {
204
- return this . _autoSelectActiveOption ;
205
- }
206
- set autoSelectActiveOption ( value : BooleanInput ) {
207
- this . _autoSelectActiveOption = coerceBooleanProperty ( value ) ;
208
- }
209
- private _autoSelectActiveOption : boolean ;
186
+ @Input ( { transform : booleanAttribute } ) autoSelectActiveOption : boolean ;
210
187
211
188
/**
212
189
* Whether the user is required to make a selection when they're interacting with the
213
190
* autocomplete. If the user moves away from the autocomplete without selecting an option from
214
191
* the list, the value will be reset. If the user opens the panel and closes it without
215
192
* interacting or selecting a value, the initial value will be kept.
216
193
*/
217
- @Input ( )
218
- get requireSelection ( ) : boolean {
219
- return this . _requireSelection ;
220
- }
221
- set requireSelection ( value : BooleanInput ) {
222
- this . _requireSelection = coerceBooleanProperty ( value ) ;
223
- }
224
- private _requireSelection : boolean ;
194
+ @Input ( { transform : booleanAttribute } ) requireSelection : boolean ;
225
195
226
196
/**
227
197
* Specify the width of the autocomplete panel. Can be any CSS sizing value, otherwise it will
228
198
* match the width of its host.
229
199
*/
230
200
@Input ( ) panelWidth : string | number ;
231
201
202
+ /** Whether ripples are disabled within the autocomplete panel. */
203
+ @Input ( { transform : booleanAttribute } ) disableRipple : boolean ;
204
+
232
205
/** Event that is emitted whenever an option from the list is selected. */
233
206
@Output ( ) readonly optionSelected : EventEmitter < MatAutocompleteSelectedEvent > =
234
207
new EventEmitter < MatAutocompleteSelectedEvent > ( ) ;
@@ -268,16 +241,15 @@ export class MatAutocomplete
268
241
_classList : { [ key : string ] : boolean } = { } ;
269
242
270
243
/** Whether checkmark indicator for single-selection options is hidden. */
271
- @Input ( )
244
+ @Input ( { transform : booleanAttribute } )
272
245
get hideSingleSelectionIndicator ( ) : boolean {
273
246
return this . _hideSingleSelectionIndicator ;
274
247
}
275
- set hideSingleSelectionIndicator ( value : BooleanInput ) {
276
- this . _hideSingleSelectionIndicator = coerceBooleanProperty ( value ) ;
248
+ set hideSingleSelectionIndicator ( value : boolean ) {
249
+ this . _hideSingleSelectionIndicator = value ;
277
250
this . _syncParentProperties ( ) ;
278
251
}
279
- private _hideSingleSelectionIndicator : boolean =
280
- this . _defaults . hideSingleSelectionIndicator ?? false ;
252
+ private _hideSingleSelectionIndicator : boolean ;
281
253
282
254
/** Syncs the parent state with the individual options. */
283
255
_syncParentProperties ( ) : void {
@@ -303,16 +275,15 @@ export class MatAutocomplete
303
275
@Inject ( MAT_AUTOCOMPLETE_DEFAULT_OPTIONS ) protected _defaults : MatAutocompleteDefaultOptions ,
304
276
platform ?: Platform ,
305
277
) {
306
- super ( ) ;
307
-
308
278
// TODO(crisbeto): the problem that the `inertGroups` option resolves is only present on
309
279
// Safari using VoiceOver. We should occasionally check back to see whether the bug
310
280
// wasn't resolved in VoiceOver, and if it has, we can remove this and the `inertGroups`
311
281
// option altogether.
312
282
this . inertGroups = platform ?. SAFARI || false ;
313
- this . _autoActiveFirstOption = ! ! _defaults . autoActiveFirstOption ;
314
- this . _autoSelectActiveOption = ! ! _defaults . autoSelectActiveOption ;
315
- this . _requireSelection = ! ! _defaults . requireSelection ;
283
+ this . autoActiveFirstOption = ! ! _defaults . autoActiveFirstOption ;
284
+ this . autoSelectActiveOption = ! ! _defaults . autoSelectActiveOption ;
285
+ this . requireSelection = ! ! _defaults . requireSelection ;
286
+ this . _hideSingleSelectionIndicator = this . _defaults . hideSingleSelectionIndicator ?? false ;
316
287
}
317
288
318
289
ngAfterContentInit ( ) {
0 commit comments