|
1 | 1 | import {FocusKeyManager} from '@angular/cdk/a11y';
|
2 | 2 | import {Directionality, Direction} from '@angular/cdk/bidi';
|
3 |
| -import {BACKSPACE, DELETE, ENTER, LEFT_ARROW, RIGHT_ARROW, SPACE, TAB} from '@angular/cdk/keycodes'; |
| 3 | +import { |
| 4 | + BACKSPACE, |
| 5 | + DELETE, |
| 6 | + ENTER, |
| 7 | + LEFT_ARROW, |
| 8 | + RIGHT_ARROW, |
| 9 | + SPACE, |
| 10 | + TAB, |
| 11 | + HOME, |
| 12 | + END, |
| 13 | +} from '@angular/cdk/keycodes'; |
4 | 14 | import {
|
5 | 15 | createKeyboardEvent,
|
6 | 16 | dispatchFakeEvent,
|
@@ -296,6 +306,36 @@ describe('MatChipList', () => {
|
296 | 306 | .toBe(initialActiveIndex, 'Expected focused item not to have changed.');
|
297 | 307 | });
|
298 | 308 |
|
| 309 | + it('should focus the first item when pressing HOME', () => { |
| 310 | + const nativeChips = chipListNativeElement.querySelectorAll('mat-chip'); |
| 311 | + const lastNativeChip = nativeChips[nativeChips.length - 1] as HTMLElement; |
| 312 | + const HOME_EVENT = createKeyboardEvent('keydown', HOME, lastNativeChip); |
| 313 | + const array = chips.toArray(); |
| 314 | + const lastItem = array[array.length - 1]; |
| 315 | + |
| 316 | + lastItem.focus(); |
| 317 | + expect(manager.activeItemIndex).toBe(array.length - 1); |
| 318 | + |
| 319 | + chipListInstance._keydown(HOME_EVENT); |
| 320 | + fixture.detectChanges(); |
| 321 | + |
| 322 | + expect(manager.activeItemIndex).toBe(0); |
| 323 | + expect(HOME_EVENT.defaultPrevented).toBe(true); |
| 324 | + }); |
| 325 | + |
| 326 | + it('should focus the last item when pressing END', () => { |
| 327 | + const nativeChips = chipListNativeElement.querySelectorAll('mat-chip'); |
| 328 | + const END_EVENT = createKeyboardEvent('keydown', END, nativeChips[0]); |
| 329 | + |
| 330 | + expect(manager.activeItemIndex).toBe(-1); |
| 331 | + |
| 332 | + chipListInstance._keydown(END_EVENT); |
| 333 | + fixture.detectChanges(); |
| 334 | + |
| 335 | + expect(manager.activeItemIndex).toBe(chips.length - 1); |
| 336 | + expect(END_EVENT.defaultPrevented).toBe(true); |
| 337 | + }); |
| 338 | + |
299 | 339 | });
|
300 | 340 |
|
301 | 341 | describe('RTL', () => {
|
|
0 commit comments