File tree 2 files changed +18
-2
lines changed
2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -1387,7 +1387,7 @@ describe('MatChipList', () => {
1387
1387
} ) ;
1388
1388
} ) ;
1389
1389
1390
- it ( 'should preselected chip as selected inside an OnPush component' , fakeAsync ( ( ) => {
1390
+ it ( 'should preselect chip as selected inside an OnPush component' , fakeAsync ( ( ) => {
1391
1391
fixture = createComponent ( PreselectedChipInsideOnPush ) ;
1392
1392
fixture . detectChanges ( ) ;
1393
1393
tick ( ) ;
@@ -1397,6 +1397,21 @@ describe('MatChipList', () => {
1397
1397
. withContext ( 'Expected first chip to be selected.' ) . toContain ( 'mat-chip-selected' ) ;
1398
1398
} ) ) ;
1399
1399
1400
+ it ( 'should not throw when accessing the selected value too early in single selection mode' ,
1401
+ fakeAsync ( ( ) => {
1402
+ fixture = createComponent ( StandardChipList ) ;
1403
+ const chipList = fixture . debugElement . query ( By . directive ( MatChipList ) ) . componentInstance ;
1404
+ expect ( ( ) => chipList . selected ) . not . toThrow ( ) ;
1405
+ } ) ) ;
1406
+
1407
+ it ( 'should not throw when accessing the selected value too early in multi selection mode' ,
1408
+ fakeAsync ( ( ) => {
1409
+ fixture = createComponent ( StandardChipList ) ;
1410
+ const chipList = fixture . debugElement . query ( By . directive ( MatChipList ) ) . componentInstance ;
1411
+ chipList . multiple = true ;
1412
+ expect ( ( ) => chipList . selected ) . not . toThrow ( ) ;
1413
+ } ) ) ;
1414
+
1400
1415
function createComponent < T > ( component : Type < T > , providers : Provider [ ] = [ ] , animationsModule :
1401
1416
Type < NoopAnimationsModule > | Type < BrowserAnimationsModule > = NoopAnimationsModule ) :
1402
1417
ComponentFixture < T > {
Original file line number Diff line number Diff line change @@ -160,7 +160,8 @@ export class MatChipList extends _MatChipListBase implements MatFormFieldControl
160
160
161
161
/** The array of selected chips inside chip list. */
162
162
get selected ( ) : MatChip [ ] | MatChip {
163
- return this . multiple ? this . _selectionModel . selected : this . _selectionModel . selected [ 0 ] ;
163
+ return this . multiple ? ( this . _selectionModel ?. selected || [ ] ) :
164
+ this . _selectionModel ?. selected [ 0 ] ;
164
165
}
165
166
166
167
/** The ARIA role applied to the chip list. */
You can’t perform that action at this time.
0 commit comments