File tree Expand file tree Collapse file tree 4 files changed +4
-24
lines changed Expand file tree Collapse file tree 4 files changed +4
-24
lines changed Original file line number Diff line number Diff line change @@ -82,28 +82,15 @@ describe('Key managers', () => {
82
82
spyOn ( keyManager , 'setActiveItem' ) . and . callThrough ( ) ;
83
83
} ) ;
84
84
85
- it ( 'should maintain the active item if the amount of items changes' , fakeAsync ( ( ) => {
85
+ it ( 'should maintain the active item if the amount of items changes' , ( ) => {
86
86
expect ( keyManager . activeItemIndex ) . toBe ( 0 ) ;
87
87
expect ( keyManager . activeItem ! . getLabel ( ) ) . toBe ( 'one' ) ;
88
88
itemList . reset ( [ new FakeFocusable ( 'zero' ) , ...itemList . toArray ( ) ] ) ;
89
89
itemList . notifyOnChanges ( ) ;
90
- tick ( ) ;
91
90
92
91
expect ( keyManager . activeItemIndex ) . toBe ( 1 ) ;
93
92
expect ( keyManager . activeItem ! . getLabel ( ) ) . toBe ( 'one' ) ;
94
- } ) ) ;
95
-
96
- it ( 'should keep the active item in sync if the active item is removed' , fakeAsync ( ( ) => {
97
- expect ( keyManager . activeItemIndex ) . toBe ( 0 ) ;
98
- expect ( keyManager . activeItem ! . getLabel ( ) ) . toBe ( 'one' ) ;
99
-
100
- itemList . reset ( itemList . toArray ( ) . slice ( 1 ) ) ;
101
- itemList . notifyOnChanges ( ) ;
102
- tick ( ) ;
103
-
104
- expect ( keyManager . activeItemIndex ) . toBe ( 0 ) ;
105
- expect ( keyManager . activeItem ! . getLabel ( ) ) . toBe ( 'two' ) ;
106
- } ) ) ;
93
+ } ) ;
107
94
108
95
it ( 'should start off the activeItem as null' , ( ) => {
109
96
expect ( new ListKeyManager ( [ ] ) . activeItem ) . toBeNull ( ) ;
Original file line number Diff line number Diff line change @@ -70,11 +70,8 @@ export class ListKeyManager<T extends ListKeyManagerOption> {
70
70
const itemArray = newItems . toArray ( ) ;
71
71
const newIndex = itemArray . indexOf ( this . _activeItem ) ;
72
72
73
- if ( newIndex !== this . _activeItemIndex ) {
74
- // Timeout is required to avoid "changed after checked" errors.
75
- setTimeout ( ( ) => {
76
- this . setActiveItem ( newIndex > - 1 ? newIndex : this . _activeItemIndex ) ;
77
- } , 0 ) ;
73
+ if ( newIndex > - 1 && newIndex !== this . _activeItemIndex ) {
74
+ this . _activeItemIndex = newIndex ;
78
75
}
79
76
}
80
77
} ) ;
Original file line number Diff line number Diff line change @@ -1176,7 +1176,6 @@ describe('MDC-based MatMenu', () => {
1176
1176
fixture . detectChanges ( ) ;
1177
1177
tick ( 500 ) ;
1178
1178
fixture . detectChanges ( ) ;
1179
- tick ( ) ;
1180
1179
1181
1180
expect ( fixture . componentInstance . items . length ) . toBe ( 0 ) ;
1182
1181
} ) ) ;
@@ -1202,7 +1201,6 @@ describe('MDC-based MatMenu', () => {
1202
1201
. toBe ( true ) ;
1203
1202
tick ( 500 ) ;
1204
1203
fixture . detectChanges ( ) ;
1205
- tick ( ) ;
1206
1204
1207
1205
expect ( trigger . menuOpen ) . withContext ( 'Expected menu to be closed' ) . toBe ( false ) ;
1208
1206
} ) ) ;
Original file line number Diff line number Diff line change @@ -1171,7 +1171,6 @@ describe('MatMenu', () => {
1171
1171
fixture . detectChanges ( ) ;
1172
1172
tick ( 500 ) ;
1173
1173
fixture . detectChanges ( ) ;
1174
- tick ( ) ;
1175
1174
1176
1175
expect ( fixture . componentInstance . items . length ) . toBe ( 0 ) ;
1177
1176
} ) ) ;
@@ -1197,7 +1196,6 @@ describe('MatMenu', () => {
1197
1196
. toBe ( true ) ;
1198
1197
tick ( 500 ) ;
1199
1198
fixture . detectChanges ( ) ;
1200
- tick ( ) ;
1201
1199
1202
1200
expect ( trigger . menuOpen ) . withContext ( 'Expected menu to be closed' ) . toBe ( false ) ;
1203
1201
} ) ) ;
You can’t perform that action at this time.
0 commit comments