From ae6795238146833d7813e3882bb2593df155ea1b Mon Sep 17 00:00:00 2001 From: AdvanceOrange <2422665951@qq.com> Date: Mon, 14 Feb 2022 14:57:01 +0800 Subject: [PATCH] fix(module:date-picker): fix disable time when date changes (#7236) Co-authored-by: hufan --- .../date-picker/date-picker.component.spec.ts | 40 +++++++++++++++++++ .../date-picker/date-range-popup.component.ts | 2 + 2 files changed, 42 insertions(+) diff --git a/components/date-picker/date-picker.component.spec.ts b/components/date-picker/date-picker.component.spec.ts index 50fae66b3d..bd9246b661 100644 --- a/components/date-picker/date-picker.component.spec.ts +++ b/components/date-picker/date-picker.component.spec.ts @@ -865,6 +865,46 @@ describe('NzDatePickerComponent', () => { expect(getPickerInput(fixture.debugElement).value).toBe(''); })); + it('should support updating the disabledtime state when the current time changes', fakeAsync(() => { + fixtureInstance.nzShowTime = true; + fixtureInstance.nzDisabledTime = (current: Date) => ({ + nzDisabledHours: () => { + if (current) { + if (current.getMonth() === 2) { + return [0, 1, 2]; + } else { + return [4, 5, 6]; + } + } else { + return [7, 8, 9]; + } + }, + nzDisabledMinutes: () => [], + nzDisabledSeconds: () => [] + }); + fixture.detectChanges(); + openPickerByClickTrigger(); + + // input disabled value + const input = getPickerInput(fixture.debugElement); + typeInElement('2020-03-14 00:00:00', input); + fixture.detectChanges(); + expect( + queryFromOverlay('.ant-picker-time-panel-column li:nth-child(3)').classList.contains( + 'ant-picker-time-panel-cell-disabled' + ) + ).toBeTruthy(); + + // input disabled value + typeInElement('2020-04-14 00:00:00', input); + fixture.detectChanges(); + expect( + queryFromOverlay('.ant-picker-time-panel-column li:nth-child(5)').classList.contains( + 'ant-picker-time-panel-cell-disabled' + ) + ).toBeTruthy(); + })); + it('should support nzRenderExtraFooter', fakeAsync(() => { fixtureInstance.nzRenderExtraFooter = () => fixtureInstance.tplExtraFooter; fixture.detectChanges(); diff --git a/components/date-picker/date-range-popup.component.ts b/components/date-picker/date-range-popup.component.ts index f0bad855c5..5c0b410135 100644 --- a/components/date-picker/date-range-popup.component.ts +++ b/components/date-picker/date-range-popup.component.ts @@ -362,6 +362,8 @@ export class DateRangePopupComponent implements OnInit, OnChanges, OnDestroy { this.datePickerService.emitValue$.next(); } } + + this.buildTimeOptions(); } reversedPart(part: RangePartType): RangePartType {