|
1 |
| -import {Component, Injector, Provider, signal, ViewChild, ViewEncapsulation} from '@angular/core'; |
| 1 | +import { |
| 2 | + Component, |
| 3 | + inject, |
| 4 | + Injector, |
| 5 | + Provider, |
| 6 | + signal, |
| 7 | + ViewChild, |
| 8 | + ViewEncapsulation, |
| 9 | +} from '@angular/core'; |
2 | 10 | import {ComponentFixture, fakeAsync, flush, TestBed} from '@angular/core/testing';
|
3 | 11 | import {DateAdapter, MATERIAL_ANIMATIONS, provideNativeDateAdapter} from '../core';
|
4 | 12 | import {
|
@@ -652,6 +660,24 @@ describe('MatTimepicker', () => {
|
652 | 660 | fixture.detectChanges();
|
653 | 661 | expect(fixture.componentInstance.timepicker.interval()).toBe(null);
|
654 | 662 | });
|
| 663 | + |
| 664 | + it('should be able to apply custom options template', () => { |
| 665 | + const fixture = TestBed.createComponent(TimepickerOptionTemplate); |
| 666 | + fixture.detectChanges(); |
| 667 | + |
| 668 | + getInput(fixture).click(); |
| 669 | + fixture.detectChanges(); |
| 670 | + expect(getOptions().map(o => o.textContent.trim())).toEqual([ |
| 671 | + '12:00 AM (off-hours)', |
| 672 | + '3:00 AM (off-hours)', |
| 673 | + '6:00 AM (off-hours)', |
| 674 | + '9:00 AM (working hours)', |
| 675 | + '12:00 PM (working hours)', |
| 676 | + '3:00 PM (working hours)', |
| 677 | + '6:00 PM (off-hours)', |
| 678 | + '9:00 PM (off-hours)', |
| 679 | + ]); |
| 680 | + }); |
655 | 681 | });
|
656 | 682 |
|
657 | 683 | describe('mat-form-field integration', () => {
|
@@ -1512,3 +1538,28 @@ class TimepickerWithoutInput {
|
1512 | 1538 | encapsulation: ViewEncapsulation.ShadowDom,
|
1513 | 1539 | })
|
1514 | 1540 | class TimepickerInShadowDom {}
|
| 1541 | + |
| 1542 | +@Component({ |
| 1543 | + template: ` |
| 1544 | + <input [matTimepicker]="picker" /> |
| 1545 | + <mat-timepicker #picker interval="3h"> |
| 1546 | + <ng-template let-option> |
| 1547 | + {{ option.label }} |
| 1548 | + {{ (dateAdapter.compareTime(option.value, workStartTime) > 0 && dateAdapter.compareTime(option.value, workEndTime) < 0) ? '(working hours)' : '(off-hours)' }} |
| 1549 | + </ng-template> |
| 1550 | + </mat-timepicker> |
| 1551 | + `, |
| 1552 | + imports: [MatTimepicker, MatTimepickerInput], |
| 1553 | +}) |
| 1554 | +class TimepickerOptionTemplate { |
| 1555 | + readonly dateAdapter = inject<DateAdapter<Date>>(DateAdapter); |
| 1556 | + readonly workStartTime: Date; |
| 1557 | + readonly workEndTime: Date; |
| 1558 | + |
| 1559 | + constructor() { |
| 1560 | + this.workStartTime = new Date(); |
| 1561 | + this.workStartTime.setHours(8, 30, 0); |
| 1562 | + this.workEndTime = new Date(); |
| 1563 | + this.workEndTime.setHours(17, 0, 0); |
| 1564 | + } |
| 1565 | +} |
0 commit comments