Skip to content

fix(timepicker): Add value updates after changing the format (#UIM-247) #380

Merged
merged 1 commit into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/mosaic/timepicker/timepicker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,31 @@ describe('McTimepicker', () => {
'broken fallback to default time format');
});
});

it('When the format updates', () => {
testComponent.timeFormat = 'HH:mm:ss';
testComponent.timeValue = moment('1970-01-01 00:00:00');
fixture.detectChanges();
lskramarov marked this conversation as resolved.
Show resolved Hide resolved

return fixture.whenStable()
.then(() => {
expect(inputElementDebug.nativeElement.value).toBe(
'00:00:00',
'mismatch time format'
);

testComponent.timeFormat = 'HH:mm';
fixture.detectChanges();

return fixture.whenStable();
})
.then(() => {
expect(inputElementDebug.nativeElement.value).toBe(
'00:00',
'mismatch time format'
);
});
});
});

describe('Convert user input', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/mosaic/timepicker/timepicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,9 @@ export class McTimepicker<D> extends McTimepickerMixinBase
.map((timeFormatKey) => TimeFormats[timeFormatKey])
.indexOf(formatValue) > -1 ? formatValue : DEFAULT_TIME_FORMAT;

(this.ngControl.control as FormControl).updateValueAndValidity();
this.placeholder = TIMEFORMAT_PLACEHOLDERS[this._timeFormat];

setTimeout(() => this.applyInputChanges({ doTimestringReformat: true }));
}

private _timeFormat: TimeFormats;
Expand Down