Skip to content

Commit

Permalink
fix(module:time-picker): ngModelChange not work (#4944)
Browse files Browse the repository at this point in the history
* fix(module:time-picker): ngModelChange not work

* fix: update typescirpt version
  • Loading branch information
wenqi73 authored Mar 26, 2020
1 parent c4d87c3 commit a6ecdb9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
1 change: 0 additions & 1 deletion components/time-picker/time-picker-panel.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ export class NzTimePickerPanelComponent implements ControlValueAccessor, OnInit,
selectHour(hour: { index: number; disabled: boolean }): void {
this.time.setHours(hour.index, hour.disabled);
this.scrollToSelected(this.hourListElement.nativeElement, hour.index, 120, 'hour');

if (!!this._disabledMinutes) {
this.buildMinutes();
}
Expand Down
23 changes: 23 additions & 0 deletions components/time-picker/time-picker.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { async, ComponentFixture, fakeAsync, inject, TestBed, tick } from '@angu
import { FormsModule } from '@angular/forms';
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { dispatchMouseEvent } from 'ng-zorro-antd/core/testing';
import { NzI18nModule } from '../i18n/nz-i18n.module';
import { NzTimePickerComponent } from './time-picker.component';
import { NzTimePickerModule } from './time-picker.module';
Expand Down Expand Up @@ -101,6 +102,26 @@ describe('time-picker', () => {
fixture.detectChanges();
expect(testComponent.nzTimePickerComponent.nzFormat).toBe('h:mm:ss a');
});
it('should support ngModelChange', fakeAsync(() => {
testComponent.date = new Date('2020-03-26 11:33:00');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
const nzOnChange = spyOn(testComponent, 'onChange');
testComponent.open = true;
fixture.detectChanges();
tick(500);
fixture.detectChanges();
expect(overlayContainer.getContainerElement().querySelector('.ant-picker-time-panel-cell-selected > div')!.textContent).toBe('11');

dispatchMouseEvent(overlayContainer.getContainerElement().querySelector('.ant-picker-time-panel-cell')!, 'click');
fixture.detectChanges();
tick(500);
fixture.detectChanges();
expect(nzOnChange).toHaveBeenCalled();
const result = (nzOnChange.calls.allArgs()[0] as Date[])[0];
expect(result.getHours()).toBe(0);
}));
});
});

Expand All @@ -109,6 +130,7 @@ describe('time-picker', () => {
<nz-time-picker
[nzAutoFocus]="autoFocus"
[(ngModel)]="date"
(ngModelChange)="onChange($event)"
[(nzOpen)]="open"
(nzOpenChange)="openChange($event)"
[nzDisabled]="disabled"
Expand All @@ -123,5 +145,6 @@ export class NzTestTimePickerComponent {
date = new Date();
disabled = false;
use12Hours = false;
onChange(): void {}
@ViewChild(NzTimePickerComponent, { static: false }) nzTimePickerComponent: NzTimePickerComponent;
}
1 change: 1 addition & 0 deletions components/time-picker/time-picker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const NZ_CONFIG_COMPONENT_NAME = 'timePicker';
[nzClearText]="nzClearText"
[nzAllowEmpty]="nzAllowEmpty"
[(ngModel)]="value"
(ngModelChange)="setValue($event)"
(closePanel)="close()"
>
</nz-time-picker-panel>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"gulp-clean": "^0.4.0",
"husky": "^3.0.4",
"immer": "^6.0.1",
"intersection-observer": "^0.7.0",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.3.0",
Expand Down Expand Up @@ -114,9 +115,8 @@
"tsickle": "^0.38.1",
"tslib": "^1.10.0",
"tslint": "~5.18.0",
"typescript": "~3.7.4",
"typescript": "~3.8.0",
"yaml-front-matter": "^4.0.0",
"intersection-observer": "^0.7.0",
"zone.js": "~0.10.2"
},
"lint-staged": {
Expand Down

0 comments on commit a6ecdb9

Please sign in to comment.