|
7 | 7 | LEFT_ARROW,
|
8 | 8 | RIGHT_ARROW,
|
9 | 9 | SPACE,
|
10 |
| - TAB |
| 10 | + TAB, |
| 11 | + HOME, |
| 12 | + END |
11 | 13 | } from '@angular/cdk/keycodes';
|
12 | 14 | import {
|
13 | 15 | createFakeEvent,
|
@@ -443,6 +445,55 @@ describe('MDC-based MatChipGrid', () => {
|
443 | 445 | expect(manager.activeRowIndex).toBe(0);
|
444 | 446 | expect(manager.activeColumnIndex).toBe(0);
|
445 | 447 | });
|
| 448 | + |
| 449 | + it('should move focus to the first chip when pressing HOME', () => { |
| 450 | + setupStandardGrid(); |
| 451 | + manager = chipGridInstance._keyManager; |
| 452 | + |
| 453 | + const nativeChips = chipGridNativeElement.querySelectorAll('mat-chip-row'); |
| 454 | + const lastNativeChip = nativeChips[nativeChips.length - 1] as HTMLElement; |
| 455 | + |
| 456 | + const HOME_EVENT: KeyboardEvent = |
| 457 | + createKeyboardEvent('keydown', HOME, undefined, lastNativeChip); |
| 458 | + const array = chips.toArray(); |
| 459 | + const lastItem = array[array.length - 1]; |
| 460 | + |
| 461 | + lastItem.focus(); |
| 462 | + expect(manager.activeRowIndex).toBe(4); |
| 463 | + expect(manager.activeColumnIndex).toBe(0); |
| 464 | + |
| 465 | + chipGridInstance._keydown(HOME_EVENT); |
| 466 | + fixture.detectChanges(); |
| 467 | + |
| 468 | + expect(HOME_EVENT.defaultPrevented).toBe(true); |
| 469 | + expect(manager.activeRowIndex).toBe(0); |
| 470 | + expect(manager.activeColumnIndex).toBe(0); |
| 471 | + }); |
| 472 | + |
| 473 | + it('should move focus to the last chip when pressing END', () => { |
| 474 | + setupStandardGrid(); |
| 475 | + manager = chipGridInstance._keyManager; |
| 476 | + |
| 477 | + const nativeChips = chipGridNativeElement.querySelectorAll('mat-chip-row'); |
| 478 | + const firstNativeChip = nativeChips[0] as HTMLElement; |
| 479 | + |
| 480 | + const END_EVENT: KeyboardEvent = |
| 481 | + createKeyboardEvent('keydown', END, undefined, firstNativeChip); |
| 482 | + const array = chips.toArray(); |
| 483 | + const firstItem = array[0]; |
| 484 | + |
| 485 | + firstItem.focus(); |
| 486 | + expect(manager.activeRowIndex).toBe(0); |
| 487 | + expect(manager.activeColumnIndex).toBe(0); |
| 488 | + |
| 489 | + chipGridInstance._keydown(END_EVENT); |
| 490 | + fixture.detectChanges(); |
| 491 | + |
| 492 | + expect(END_EVENT.defaultPrevented).toBe(true); |
| 493 | + expect(manager.activeRowIndex).toBe(4); |
| 494 | + expect(manager.activeColumnIndex).toBe(0); |
| 495 | + }); |
| 496 | + |
446 | 497 | });
|
447 | 498 | });
|
448 | 499 |
|
|
0 commit comments