diff --git a/demo/src/app/components/+timepicker/demos/config/config.ts b/demo/src/app/components/+timepicker/demos/config/config.ts
index cfca9cb911..3ab92d2757 100644
--- a/demo/src/app/components/+timepicker/demos/config/config.ts
+++ b/demo/src/app/components/+timepicker/demos/config/config.ts
@@ -9,7 +9,9 @@ export function getTimepickerConfig(): TimepickerConfig {
minuteStep: 10,
showMeridian: false,
readonlyInput: false,
- mousewheel: true
+ mousewheel: true,
+ showMinutes: true,
+ showSeconds: false
});
}
diff --git a/demo/src/app/components/+timepicker/demos/index.ts b/demo/src/app/components/+timepicker/demos/index.ts
index 3e7ab3e763..1d3830425e 100644
--- a/demo/src/app/components/+timepicker/demos/index.ts
+++ b/demo/src/app/components/+timepicker/demos/index.ts
@@ -5,7 +5,7 @@ import { DemoTimepickerDisabledComponent } from './disabled/disabled';
import { DemoTimepickerCustomComponent } from './custom/custom';
import { DemoTimepickerDynamicComponent } from './dynamic/dynamic';
import { DemoTimepickerMinMaxComponent } from './min-max/min-max';
-import { DemoTimepickerSecondsComponent } from './seconds/seconds';
+import { DemoTimepickerToggleMinutesSecondsComponent } from './toggle-minutes-seconds/toggle-minutes-seconds';
import { DemoTimepickerMousewheelArrowkeysComponent } from './mousewheel-arrowkeys/mousewheel-arrowkeys';
import { DemoTimepickerCustomValidationComponent } from './custom-validation/custom-validation';
@@ -17,7 +17,7 @@ export const DEMO_COMPONENTS = [
DemoTimepickerDisabledComponent,
DemoTimepickerCustomComponent,
DemoTimepickerDynamicComponent,
- DemoTimepickerSecondsComponent,
+ DemoTimepickerToggleMinutesSecondsComponent,
DemoTimepickerMousewheelArrowkeysComponent,
DemoTimepickerCustomValidationComponent
];
diff --git a/demo/src/app/components/+timepicker/demos/seconds/seconds.html b/demo/src/app/components/+timepicker/demos/seconds/seconds.html
deleted file mode 100644
index 33e9d95e40..0000000000
--- a/demo/src/app/components/+timepicker/demos/seconds/seconds.html
+++ /dev/null
@@ -1,3 +0,0 @@
-
Time is: {{myTime}}diff --git a/demo/src/app/components/+timepicker/demos/seconds/seconds.ts b/demo/src/app/components/+timepicker/demos/seconds/seconds.ts deleted file mode 100644 index 62e3a12d2f..0000000000 --- a/demo/src/app/components/+timepicker/demos/seconds/seconds.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Component } from '@angular/core'; - -@Component({ - selector: 'demo-timepicker-seconds', - templateUrl: './seconds.html' -}) -export class DemoTimepickerSecondsComponent { - myTime: Date = new Date(); - showSec: boolean = true; -} diff --git a/demo/src/app/components/+timepicker/demos/toggle-minutes-seconds/toggle-minutes-seconds.html b/demo/src/app/components/+timepicker/demos/toggle-minutes-seconds/toggle-minutes-seconds.html new file mode 100644 index 0000000000..e6f1bc4b9e --- /dev/null +++ b/demo/src/app/components/+timepicker/demos/toggle-minutes-seconds/toggle-minutes-seconds.html @@ -0,0 +1,10 @@ +
Time is: {{myTime}}+ + + diff --git a/demo/src/app/components/+timepicker/demos/toggle-minutes-seconds/toggle-minutes-seconds.ts b/demo/src/app/components/+timepicker/demos/toggle-minutes-seconds/toggle-minutes-seconds.ts new file mode 100644 index 0000000000..f4af2cc25d --- /dev/null +++ b/demo/src/app/components/+timepicker/demos/toggle-minutes-seconds/toggle-minutes-seconds.ts @@ -0,0 +1,20 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'demo-timepicker-seconds', + templateUrl: './toggle-minutes-seconds.html' +}) +export class DemoTimepickerToggleMinutesSecondsComponent { + myTime: Date = new Date(); + showMin: boolean = true; + showSec: boolean = true; + + toggleMinutes(): void { + this.showMin = !this.showMin; + } + + toggleSeconds(): void { + this.showSec = !this.showSec; + } + +} diff --git a/demo/src/app/components/+timepicker/timepicker-section.list.ts b/demo/src/app/components/+timepicker/timepicker-section.list.ts index 83a0329390..dcd79d6be0 100644 --- a/demo/src/app/components/+timepicker/timepicker-section.list.ts +++ b/demo/src/app/components/+timepicker/timepicker-section.list.ts @@ -1,7 +1,7 @@ import { DemoTimepickerBasicComponent } from './demos/basic/basic'; import { DemoTimepickerMeridianComponent } from './demos/meridian/meridian'; import { DemoTimepickerMinMaxComponent } from './demos/min-max/min-max'; -import { DemoTimepickerSecondsComponent } from './demos/seconds/seconds'; +import { DemoTimepickerToggleMinutesSecondsComponent } from './demos/toggle-minutes-seconds/toggle-minutes-seconds'; import { DemoTimepickerDisabledComponent } from './demos/disabled/disabled'; import { DemoTimepickerCustomComponent } from './demos/custom/custom'; import { DemoTimepickerCustomValidationComponent } from './demos/custom-validation/custom-validation'; @@ -55,11 +55,11 @@ export const demoComponentContent: ContentSection[] = [ outlet: DemoTimepickerMinMaxComponent }, { - title: 'Show seconds', - anchor: 'seconds', - component: require('!!raw-loader?lang=typescript!./demos/seconds/seconds'), - html: require('!!raw-loader?lang=markup!./demos/seconds/seconds.html'), - outlet: DemoTimepickerSecondsComponent + title: 'Toggle minutes/seconds', + anchor: 'toggleMinutesSeconds', + component: require('!!raw-loader?lang=typescript!./demos/toggle-minutes-seconds/toggle-minutes-seconds'), + html: require('!!raw-loader?lang=markup!./demos/toggle-minutes-seconds/toggle-minutes-seconds.html'), + outlet: DemoTimepickerToggleMinutesSecondsComponent }, { title: 'Disabled', diff --git a/demo/src/ng-api-doc.ts b/demo/src/ng-api-doc.ts index d10014f7f9..65fd9352d3 100644 --- a/demo/src/ng-api-doc.ts +++ b/demo/src/ng-api-doc.ts @@ -2622,10 +2622,15 @@ export const ngdoc: any = { "type": "boolean", "description": "" }, + { + "name": "showMinutes", + "type": "boolean", + "description": "
showMinutes: {{showMin}}
showSeconds: {{showSec}}
if true minutes in timepicker will be shown
\n" + }, { "name": "showSeconds", "type": "boolean", - "description": "" + "description": "if true seconds in timepicker will be shown
\n" }, { "name": "showSpinners", @@ -2705,6 +2710,12 @@ export const ngdoc: any = { "type": "boolean", "description": "if true works in 12H mode and displays AM/PM. If false works in 24H mode and hides AM/PM
\n" }, + { + "name": "showMinutes", + "defaultValue": "true", + "type": "boolean", + "description": "show minutes in timepicker
\n" + }, { "name": "showSeconds", "defaultValue": "false", diff --git a/src/spec/timepicker/timepicker.component.spec.ts b/src/spec/timepicker/timepicker.component.spec.ts index f000b8ac90..7eb6a767e2 100644 --- a/src/spec/timepicker/timepicker.component.spec.ts +++ b/src/spec/timepicker/timepicker.component.spec.ts @@ -287,6 +287,20 @@ describe('Component: timepicker', () => { }); }); + describe('hide minutes fields with property of showMinutes', () => { + beforeEach(() => { + fixture = TestBed.createComponent(TimepickerComponent); + fixture.detectChanges(); + component = fixture.componentInstance; + inputMinutes = getInputElements(fixture)[1]; + }); + it('should hide minutes field when property showMinutes is == false', () => { + component.showMinutes = false; + fixture.detectChanges(); + expect(inputSeconds).toBeFalsy(); + }); + }); + describe('display seconds fields with property of showSeconds', () => { beforeEach(() => { fixture = TestBed.createComponent(TimepickerComponent); @@ -939,6 +953,17 @@ describe('Component: timepicker', () => { expect(inputHours.value).toBe(''); expect(inputMinutes.value).toBe(''); }); + + it('should ignore minutes for validation if showMinutes flag == false', () => { + component.showMinutes = false; + const methodSpy = spyOn(component, 'onChange').and.callThrough(); + component.hours = '12'; + component.minutes = '99'; + component._updateTime(); + fixture.detectChanges(); + expect(methodSpy).not.toHaveBeenCalled(); + }); + // не верное значение поля должно сбрасывать время it('should clear model if values are invalid', () => { component.showSeconds = true; diff --git a/src/timepicker/timepicker.component.html b/src/timepicker/timepicker.component.html index 15c185ee17..0a685e2429 100644 --- a/src/timepicker/timepicker.component.html +++ b/src/timepicker/timepicker.component.html @@ -8,9 +8,9 @@ > -