Skip to content

Commit ab38e6c

Browse files
Added new @Input named showStartTimeInputs and `showEndTimeInputs… (#1099)
* Added new `@Input` named `showStartTimeInputs` and `showEndTimeInputs` set to a `boolean` to show and hide To and From time stamp. * added changes to demo page * updated utc * updated utc * updated utc
1 parent c38f57d commit ab38e6c

File tree

5 files changed

+69
-3
lines changed

5 files changed

+69
-3
lines changed

projects/swimlane/ngx-ui/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## HEAD (unreleased)
44

5+
- Fix: (`ngx-calendar`) : Added new `@Input` named `showStartTimeInputs` and `showEndTimeInputs` set to a `boolean`.
56
- Feature (`ngx-column`): Added a new column component
67

78
## 49.2.1 (2025-06-18)

projects/swimlane/ngx-ui/src/lib/components/calendar/calendar.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
</div>
161161
</div>
162162
<div *ngIf="selectType === 'range'" class="time-inputs">
163-
<div class="time-row" *ngIf="range.startDate">
163+
<div class="time-row" *ngIf="range.startDate && showStartTimeInputs">
164164
<div>
165165
<ngx-input
166166
type="text"
@@ -207,7 +207,7 @@
207207
</button>
208208
</div>
209209
</div>
210-
<div class="time-row" *ngIf="range.endDate">
210+
<div class="time-row" *ngIf="range.endDate && showEndTimeInputs">
211211
<div>
212212
<ngx-input
213213
type="text"
@@ -234,7 +234,7 @@
234234
</ngx-input>
235235
</div>
236236
<div>
237-
<button class="ampm" type="button" [class.selected]="endAmPmVal === 'AM'" (click)="onAmPmChange('AM', 'end')">
237+
<button class="ampm" type="button" [class.selected]="endAmPmVal === 'AM'" (click)="onAmPmChange('AM', 'end')">
238238
AM
239239
</button>
240240
</div>

projects/swimlane/ngx-ui/src/lib/components/calendar/calendar.component.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ export class CalendarComponent implements OnInit, AfterViewInit, ControlValueAcc
6767
endDate: undefined
6868
};
6969

70+
@Input() showStartTimeInputs: boolean = true;
71+
@Input() showEndTimeInputs: boolean = true;
7072
@Input('minView')
7173
get minView() {
7274
return this._minView ? this._minView : CalendarView.Date;

projects/swimlane/ngx-ui/src/lib/components/calendar/calender.component.spec.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,51 @@ describe('CalendarComponent', () => {
351351
});
352352
});
353353

354+
describe('conditional time Input rendering', () => {
355+
it('should show both time inputs if both showStartTimeInputs and showEndTimeInputs are true', () => {
356+
component.range = { startDate: new Date(), endDate: new Date() };
357+
component.showStartTimeInputs = true;
358+
component.showEndTimeInputs = true;
359+
component.selectType = 'range';
360+
fixture.detectChanges();
361+
const timeRows = fixture.nativeElement.querySelectorAll('.time-row');
362+
expect(timeRows.length).toBe(2);
363+
});
364+
365+
it('should hide start time input if showStartTimeInputs is false', () => {
366+
component.range = { startDate: new Date(), endDate: new Date() };
367+
component.showStartTimeInputs = false;
368+
component.showEndTimeInputs = true;
369+
component.selectType = 'range';
370+
fixture.detectChanges();
371+
const timeRows = fixture.nativeElement.querySelectorAll('.time-row');
372+
expect(timeRows.length).toBe(1); // only end input shown
373+
});
374+
375+
it('should hide end time input if showEndTimeInputs is false', () => {
376+
component.range = { startDate: new Date(), endDate: new Date() };
377+
component.showStartTimeInputs = true;
378+
component.showEndTimeInputs = false;
379+
component.selectType = 'range';
380+
fixture.detectChanges();
381+
const timeRows = fixture.nativeElement.querySelectorAll('.time-row');
382+
expect(timeRows.length).toBe(1); // only start input shown
383+
});
384+
385+
it('should hide both time inputs if both flags are false', () => {
386+
component.showStartTimeInputs = false;
387+
component.showEndTimeInputs = false;
388+
component.range = {
389+
startDate: new Date('2024-06-01T10:00:00'),
390+
endDate: new Date('2024-06-02T18:00:00')
391+
};
392+
component.selectType = 'range';
393+
fixture.detectChanges();
394+
const timeRows = fixture.nativeElement.querySelectorAll('.time-row');
395+
expect(timeRows.length).toBe(0); // nothing rendered
396+
});
397+
});
398+
354399
describe('initializeTime', () => {
355400
it('should initialize time properties based on range start and range end', () => {
356401
const rangeStart = new Date('2024-04-04T10:30:00');

src/app/forms/calendar-page/calendar-page.component.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,24 @@ <h3>Select Range</h3>
7171
(onRangeSelect)="onRangeSelect($event)"> </ngx-calendar>]]>
7272
</app-prism>
7373

74+
<h3>Select Range - Configure ‘From’ and ‘To’ timestamps in Select Range using input flags.</h3>
75+
76+
<ngx-calendar
77+
name="calendar-range"
78+
[selectType]="'range'"
79+
[dateLabelFormat]="'YYYY MMM D'"
80+
(onRangeSelect)="onRangeSelect($event)"
81+
[showStartTimeInputs] = "true"
82+
[showEndTimeInputs] = "false"
83+
>
84+
</ngx-calendar>
85+
86+
<app-prism>
87+
<![CDATA[<ngx-calendar name="calendar-range" [selectType]="'range'" [dateLabelFormat]="'YYYY MMM D'"
88+
(onRangeSelect)="onRangeSelect($event)" [showStartTimeInputs] = "true"
89+
[showEndTimeInputs] = "true"> </ngx-calendar>]]>
90+
</app-prism>
91+
7492
<h3>Min view and Default view</h3>
7593

7694
<h4>Min view: "date" default view: "date"</h4>

0 commit comments

Comments
 (0)