Skip to content

Commit 999a915

Browse files
committed
feat(picker-base): add hideHeader prop + tests
1 parent e7553e7 commit 999a915

File tree

7 files changed

+62
-6
lines changed

7 files changed

+62
-6
lines changed

projects/igniteui-angular/src/lib/date-common/picker-base.directive.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ export abstract class PickerBaseDirective implements IToggleView, EditorProvider
8989
@Input()
9090
public headerOrientation: PickerHeaderOrientation = PickerHeaderOrientation.Horizontal;
9191

92+
/**
93+
* Gets/Sets whether the header is hidden in dialog mode.
94+
*
95+
* @example
96+
* ```html
97+
* <igx-date-picker mode="dialog" [hideHeader]="true"></igx-date-picker>
98+
* ```
99+
*/
100+
@Input({ transform: booleanAttribute })
101+
public hideHeader = false;
102+
92103
/**
93104
* Overlay settings used to display the pop-up element.
94105
*

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const DATE_PICKER_CLEAR_ICON = 'clear';
3232

3333
const CSS_CLASS_INPUT_GROUP_REQUIRED = 'igx-input-group--required';
3434
const CSS_CLASS_INPUT_GROUP_INVALID = 'igx-input-group--invalid';
35+
const CSS_CLASS_CALENDAR_HEADER = '.igx-calendar__header';
3536

3637
describe('IgxDatePicker', () => {
3738
describe('Integration tests', () => {
@@ -66,6 +67,19 @@ describe('IgxDatePicker', () => {
6667
expect(suffix).toHaveSize(1);
6768
expect(suffix[0].nativeElement.innerText).toEqual(DATE_PICKER_CLEAR_ICON);
6869
});
70+
71+
it('should hide the calendar header if hideHeader is true in dialog mode', fakeAsync(() => {
72+
const datePicker = fixture.componentInstance.datePicker;
73+
datePicker.mode = 'dialog';
74+
datePicker.hideHeader = true;
75+
datePicker.open();
76+
tick();
77+
fixture.detectChanges();
78+
79+
expect(datePicker['_calendar'].hasHeader).toBeFalse();
80+
const calendarHeader = fixture.debugElement.query(By.css(CSS_CLASS_CALENDAR_HEADER));
81+
expect(calendarHeader).toBeFalsy('Calendar header should not be present');
82+
}));
6983
});
7084

7185
describe('Events', () => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ export class IgxDatePickerComponent extends PickerBaseDirective implements Contr
954954

955955
private _initializeCalendarContainer(componentInstance: IgxCalendarContainerComponent) {
956956
this._calendar = componentInstance.calendar;
957-
this._calendar.hasHeader = !this.isDropdown;
957+
this._calendar.hasHeader = !this.isDropdown && !this.hideHeader;
958958
this._calendar.formatOptions = this.pickerCalendarFormat;
959959
this._calendar.formatViews = this.pickerFormatViews;
960960
this._calendar.locale = this.locale;

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ const CSS_CLASS_OVERLAY_CONTENT = 'igx-overlay__content';
4444
const CSS_CLASS_DATE_RANGE = 'igx-date-range-picker';
4545
const CSS_CLASS_CALENDAR_DATE = 'igx-days-view__date';
4646
const CSS_CLASS_INACTIVE_DATE = 'igx-days-view__date--inactive';
47-
const CSS_CLASS_CALENDAR_HEADER = '.igx-calendar__header-date';
47+
const CSS_CLASS_CALENDAR_HEADER_TEMPLATE = '.igx-calendar__header-date';
4848
const CSS_CLASS_CALENDAR_HEADER_TITLE = '.igx-calendar__header-year';
4949
const CSS_CLASS_CALENDAR_SUBHEADER = '.igx-calendar-picker__dates';
50+
const CSS_CLASS_CALENDAR_HEADER = '.igx-calendar__header';
5051

5152
describe('IgxDateRangePicker', () => {
5253
describe('Unit tests: ', () => {
@@ -1576,7 +1577,7 @@ describe('IgxDateRangePicker', () => {
15761577
fixture.detectChanges();
15771578

15781579
expect(dateRange['_calendar'].hasHeader).toBeTrue();
1579-
const calendarHeader = fixture.debugElement.query(By.css(CSS_CLASS_CALENDAR_HEADER));
1580+
const calendarHeader = fixture.debugElement.query(By.css(CSS_CLASS_CALENDAR_HEADER_TEMPLATE));
15801581
expect(calendarHeader).toBeTruthy('Calendar header should be present');
15811582
}));
15821583

@@ -1604,6 +1605,22 @@ describe('IgxDateRangePicker', () => {
16041605
expect(dateRange['_calendar'].headerOrientation).toBe(PickerHeaderOrientation.Vertical);
16051606
}));
16061607

1608+
it('should hide the calendar header if hideHeader is true in dialog mode', fakeAsync(() => {
1609+
fixture = TestBed.createComponent(DateRangeDefaultComponent);
1610+
fixture.detectChanges();
1611+
dateRange = fixture.componentInstance.dateRange;
1612+
1613+
dateRange.mode = 'dialog';
1614+
dateRange.hideHeader = true;
1615+
dateRange.open();
1616+
tick();
1617+
fixture.detectChanges();
1618+
1619+
expect(dateRange['_calendar'].hasHeader).toBeFalse();
1620+
const calendarHeader = fixture.debugElement.query(By.css(CSS_CLASS_CALENDAR_HEADER));
1621+
expect(calendarHeader).toBeFalsy('Calendar header should not be present');
1622+
}));
1623+
16071624
describe('Templated Calendar Header', () => {
16081625
let dateRangeDebugEl: DebugElement;
16091626
beforeEach(fakeAsync(() => {
@@ -1630,7 +1647,7 @@ describe('IgxDateRangePicker', () => {
16301647
}));
16311648

16321649
it('Should use the custom template for header', fakeAsync(() => {
1633-
const headerElement = dateRangeDebugEl.query(By.css(CSS_CLASS_CALENDAR_HEADER));
1650+
const headerElement = dateRangeDebugEl.query(By.css(CSS_CLASS_CALENDAR_HEADER_TEMPLATE));
16341651
expect(headerElement).toBeTruthy('Header element should be present');
16351652
if (headerElement) {
16361653
expect(headerElement.nativeElement.textContent.trim()).toBe('Test header');

projects/igniteui-angular/src/lib/date-range-picker/date-range-picker.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ export class IgxDateRangePickerComponent extends PickerBaseDirective
10901090

10911091
private _initializeCalendarContainer(componentInstance: IgxCalendarContainerComponent) {
10921092
this._calendar = componentInstance.calendar;
1093-
this.calendar.hasHeader = !this.isDropdown;
1093+
this._calendar.hasHeader = !this.isDropdown && !this.hideHeader;
10941094
this.calendar.locale = this.locale;
10951095
this.calendar.selection = CalendarSelection.RANGE;
10961096
this.calendar.weekStart = this.weekStart;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
<div #toggleDirective="toggle" igxToggle role="dialog" class="igx-time-picker"
6363
[ngClass]="{'igx-time-picker--dropdown': isDropdown, 'igx-time-picker--vertical': isVertical && !isDropdown}">
6464
<div class="igx-time-picker__main">
65-
@if (!isDropdown) {
65+
@if (!this.isDropdown && !this.hideHeader) {
6666
<div class="igx-time-picker__header">
6767
<h2 class="igx-time-picker__header-hour">
6868
<span>{{ selectedDate | timeFormatPipe }}</span>

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const CSS_CLASS_SECONDSLIST = '.igx-time-picker__secondsList';
3434
const CSS_CLASS_AMPMLIST = 'igx-time-picker__ampmList';
3535
const CSS_CLASS_SELECTED_ITEM = '.igx-time-picker__item--selected';
3636
const CSS_CLASS_HEADER_HOUR = '.igx-time-picker__header-hour';
37+
const CSS_CLASS_HEADER = '.igx-time-picker__header';
3738
const CSS_CLASS_OVERLAY_WRAPPER = 'igx-overlay__wrapper';
3839
const TIME_PICKER_TOGGLE_ICON = 'access_time';
3940
const TIME_PICKER_CLEAR_ICON = 'clear';
@@ -1597,6 +1598,19 @@ describe('IgxTimePicker', () => {
15971598
dialogDivVertical = timePickerDebElement.query(By.css(CSS_CLASS_TIME_PICKER_VERTICAL));
15981599
expect(dialogDivVertical).not.toBeNull();
15991600
}));
1601+
1602+
it('should hide the calendar header if hideHeader is true in dialog mode', fakeAsync(() => {
1603+
timePicker.mode = PickerInteractionMode.Dialog;
1604+
timePicker.hideHeader = true;
1605+
fixture.detectChanges();
1606+
1607+
timePicker.open();
1608+
tick();
1609+
fixture.detectChanges();
1610+
1611+
const header = fixture.debugElement.query(By.css(CSS_CLASS_HEADER));
1612+
expect(header).toBeNull();
1613+
}));
16001614
});
16011615

16021616
describe('Keyboard navigation', () => {

0 commit comments

Comments
 (0)