Skip to content

Commit 7537989

Browse files
authored
Merge pull request #8545 from IgniteUI/bpenkov/timepicker-typing-9.1
Properly parse AM/PM when typing - 9.1
2 parents a1bcd94 + bab23e4 commit 7537989

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

projects/igniteui-angular/src/lib/time-picker/time-picker.component.spec.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, ViewChild, NgModule, ElementRef, EventEmitter } from '@angular/core';
1+
import { Component, ViewChild, NgModule, ElementRef, EventEmitter, DebugElement } from '@angular/core';
22
import { async, TestBed, fakeAsync, tick, ComponentFixture } from '@angular/core/testing';
33
import { FormsModule, FormGroup, FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
44
import { By } from '@angular/platform-browser';
@@ -1766,7 +1766,10 @@ describe('IgxTimePicker', () => {
17661766

17671767
describe('Hour/minute only mode', () => {
17681768
configureTestSuite();
1769-
let fixture, timePicker, dom, input;
1769+
let fixture: ComponentFixture<IgxTimePickerDropDownSingleHourComponent>,
1770+
timePicker: IgxTimePickerComponent,
1771+
dom: DebugElement,
1772+
input: DebugElement;
17701773

17711774
beforeEach(
17721775
async(() => {
@@ -1841,6 +1844,21 @@ describe('IgxTimePicker', () => {
18411844
expect(_input.nativeElement.value).toEqual('12 AM');
18421845
}));
18431846

1847+
it('Should properly switch between AM/PM when typing', () => {
1848+
fixture.componentInstance.format = 'hh tt';
1849+
fixture.componentInstance.customDate = new Date(2018, 10, 27, 17, 45, 0, 0);
1850+
fixture.detectChanges();
1851+
1852+
input.triggerEventHandler('focus', { target: input.nativeElement });
1853+
UIInteractions.simulateTyping('pm', input, 2, 4);
1854+
fixture.detectChanges();
1855+
expect(input.nativeElement.value).toEqual('05 pm');
1856+
1857+
input.triggerEventHandler('blur', { target: input.nativeElement });
1858+
fixture.detectChanges();
1859+
expect(input.nativeElement.value).toEqual('05 PM');
1860+
});
1861+
18441862
it('Should navigate dropdown lists correctly when format contains only hours.', fakeAsync(() => {
18451863
fixture.componentInstance.format = 'hh tt';
18461864
fixture.componentInstance.customDate = new Date(2018, 10, 27, 17, 45, 0);

projects/igniteui-angular/src/lib/time-picker/time-picker.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ export class IgxTimePickerComponent implements
12911291
}
12921292

12931293
if (this.showAmPmList) {
1294-
amPM = sections[sections.length - 1];
1294+
amPM = sections[sections.length - 1].toUpperCase();
12951295

12961296
if (((this.showHoursList && date.getHours().toString() !== '12') ||
12971297
(!this.showHoursList && date.getHours().toString() <= '11')) && amPM === 'PM') {

0 commit comments

Comments
 (0)