@@ -10,14 +10,14 @@ import {FocusableOption, FocusKeyManager} from '@angular/cdk/a11y';
10
10
import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
11
11
import { SelectionModel } from '@angular/cdk/collections' ;
12
12
import {
13
- SPACE ,
13
+ A ,
14
+ DOWN_ARROW ,
15
+ END ,
14
16
ENTER ,
17
+ hasModifierKey ,
15
18
HOME ,
16
- END ,
19
+ SPACE ,
17
20
UP_ARROW ,
18
- DOWN_ARROW ,
19
- A ,
20
- hasModifierKey ,
21
21
} from '@angular/cdk/keycodes' ;
22
22
import {
23
23
AfterContentInit ,
@@ -32,25 +32,27 @@ import {
32
32
forwardRef ,
33
33
Inject ,
34
34
Input ,
35
+ OnChanges ,
35
36
OnDestroy ,
36
37
OnInit ,
37
38
Output ,
38
39
QueryList ,
40
+ SimpleChanges ,
39
41
ViewChild ,
40
42
ViewEncapsulation ,
41
- SimpleChanges ,
42
- OnChanges ,
43
43
} from '@angular/core' ;
44
+ import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ;
44
45
import {
45
- CanDisableRipple , CanDisableRippleCtor ,
46
+ CanDisableRipple ,
47
+ CanDisableRippleCtor ,
46
48
MatLine ,
47
- setLines ,
48
49
mixinDisableRipple ,
50
+ setLines ,
49
51
ThemePalette ,
50
52
} from '@angular/material/core' ;
51
- import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ;
52
53
import { Subject } from 'rxjs' ;
53
54
import { takeUntil } from 'rxjs/operators' ;
55
+
54
56
import { MatListAvatarCssMatStyler , MatListIconCssMatStyler } from './list' ;
55
57
56
58
@@ -114,9 +116,9 @@ export class MatSelectionListChange {
114
116
encapsulation : ViewEncapsulation . None ,
115
117
changeDetection : ChangeDetectionStrategy . OnPush ,
116
118
} )
117
- export class MatListOption extends _MatListOptionMixinBase
118
- implements AfterContentInit , OnDestroy , OnInit , FocusableOption , CanDisableRipple {
119
-
119
+ export class MatListOption extends _MatListOptionMixinBase implements AfterContentInit , OnDestroy ,
120
+ OnInit , FocusableOption ,
121
+ CanDisableRipple {
120
122
private _selected = false ;
121
123
private _disabled = false ;
122
124
private _hasFocus = false ;
@@ -137,11 +139,16 @@ export class MatListOption extends _MatListOptionMixinBase
137
139
set color ( newValue : ThemePalette ) { this . _color = newValue ; }
138
140
private _color : ThemePalette ;
139
141
142
+ /**
143
+ * This is set to true after the first OnChanges cycle so we don't clear the value of `selected`
144
+ * in the first cycle.
145
+ */
146
+ private _inputsInitialized = false ;
140
147
/** Value of the option */
141
148
@Input ( )
142
149
get value ( ) : any { return this . _value ; }
143
150
set value ( newValue : any ) {
144
- if ( this . selected && newValue !== this . value ) {
151
+ if ( this . selected && newValue !== this . value && this . _inputsInitialized ) {
145
152
this . selected = false ;
146
153
}
147
154
@@ -200,6 +207,7 @@ export class MatListOption extends _MatListOptionMixinBase
200
207
this . _changeDetector . markForCheck ( ) ;
201
208
}
202
209
} ) ;
210
+ this . _inputsInitialized = true ;
203
211
}
204
212
205
213
ngAfterContentInit ( ) {
0 commit comments