@@ -10,14 +10,14 @@ import {FocusableOption, FocusKeyManager} from '@angular/cdk/a11y';
1010import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
1111import { SelectionModel } from '@angular/cdk/collections' ;
1212import {
13- SPACE ,
13+ A ,
14+ DOWN_ARROW ,
15+ END ,
1416 ENTER ,
17+ hasModifierKey ,
1518 HOME ,
16- END ,
19+ SPACE ,
1720 UP_ARROW ,
18- DOWN_ARROW ,
19- A ,
20- hasModifierKey ,
2121} from '@angular/cdk/keycodes' ;
2222import {
2323 AfterContentInit ,
@@ -32,25 +32,27 @@ import {
3232 forwardRef ,
3333 Inject ,
3434 Input ,
35+ OnChanges ,
3536 OnDestroy ,
3637 OnInit ,
3738 Output ,
3839 QueryList ,
40+ SimpleChanges ,
3941 ViewChild ,
4042 ViewEncapsulation ,
41- SimpleChanges ,
42- OnChanges ,
4343} from '@angular/core' ;
44+ import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ;
4445import {
45- CanDisableRipple , CanDisableRippleCtor ,
46+ CanDisableRipple ,
47+ CanDisableRippleCtor ,
4648 MatLine ,
47- setLines ,
4849 mixinDisableRipple ,
50+ setLines ,
4951 ThemePalette ,
5052} from '@angular/material/core' ;
51- import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ;
5253import { Subject } from 'rxjs' ;
5354import { takeUntil } from 'rxjs/operators' ;
55+
5456import { MatListAvatarCssMatStyler , MatListIconCssMatStyler } from './list' ;
5557
5658
@@ -114,9 +116,9 @@ export class MatSelectionListChange {
114116 encapsulation : ViewEncapsulation . None ,
115117 changeDetection : ChangeDetectionStrategy . OnPush ,
116118} )
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 {
120122 private _selected = false ;
121123 private _disabled = false ;
122124 private _hasFocus = false ;
@@ -137,11 +139,16 @@ export class MatListOption extends _MatListOptionMixinBase
137139 set color ( newValue : ThemePalette ) { this . _color = newValue ; }
138140 private _color : ThemePalette ;
139141
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 ;
140147 /** Value of the option */
141148 @Input ( )
142149 get value ( ) : any { return this . _value ; }
143150 set value ( newValue : any ) {
144- if ( this . selected && newValue !== this . value ) {
151+ if ( this . selected && newValue !== this . value && this . _inputsInitialized ) {
145152 this . selected = false ;
146153 }
147154
@@ -200,6 +207,7 @@ export class MatListOption extends _MatListOptionMixinBase
200207 this . _changeDetector . markForCheck ( ) ;
201208 }
202209 } ) ;
210+ this . _inputsInitialized = true ;
203211 }
204212
205213 ngAfterContentInit ( ) {
0 commit comments