Skip to content

Commit 6cdc617

Browse files
committed
feat(date-picker): Rewiriting the label, #8086
1 parent 756258c commit 6cdc617

File tree

5 files changed

+39
-58
lines changed

5 files changed

+39
-58
lines changed

projects/igniteui-angular/src/lib/date-picker/README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ The DatePicker action buttons could be retemplated.
123123
| `weekStart`| `Number \| WEEKDAYS` | Sets on which day will the week start. |
124124
| `locale` | `string` | Sets the locale used for formatting and displaying the dates in the calendar. For more information check out [this](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl) page for valid formats. |
125125
| `formatOptions` | `Object` | The format options passed along with the `locale` property used for formatting the dates. |
126-
| `label` | `string` | Configure the input label text. |
127-
| `labelVisibility` | `string` | Configure the input label text visibility. |
128126
| `format` | `string` | Configure the date display format when in edit mode. Accepts formats using the d, M and y symbols, custom separators and the following pre-defined format options - shortDate, mediumDate, longDate and fullDate. |
129127
| `mask` | `string` | Configure the date editor mask. Accepts the d, M and y symbols as mask - for example dd-MM-y. |
130128
| `disabledDates` | `DateRangeDescriptor[]` | Configure the disabled dates. |
@@ -154,4 +152,4 @@ The DatePicker action buttons could be retemplated.
154152
| `selectDate` | `date: Date` | `void` | Change the calendar selection. Calling this method will emit the `onSelection` event. |
155153
| `deselectDate` | `void` | Deselects the calendar date and clear input field value. |
156154
| `triggerTodaySelection` | `void` | Selects today's date in calendar and change the input field value. |
157-
| `openDialog` | `target?: HTMLElement` | `void` | Opens the dialog or drop down, depending on the mode. |
155+
| `openDialog` | `target?: HTMLElement` | `void` | Opens the dialog or drop down, depending on the mode. |

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

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
<ng-template #labelTemplate>
2+
<ng-content select="[igxLabel]"></ng-content>
3+
</ng-template>
4+
15
<ng-template #readOnlyDatePickerTemplate>
26
<igx-input-group (click)="openDialog()">
7+
<label igxLabel *ngIf="!labelDirective">Date</label>
8+
<ng-container ngProjectAs="[igxLabel]" *ngTemplateOutlet="labelTemplate"></ng-container>
39
<igx-prefix>
410
<igx-icon>today</igx-icon>
511
</igx-prefix>
6-
<label *ngIf="labelVisibility" igxLabel>{{label}}</label>
712
<input
813
class="igx-date-picker__input-date"
914
igxInput
@@ -18,10 +23,11 @@
1823

1924
<ng-template #editableDatePickerTemplate>
2025
<igx-input-group #editableInputGroup>
26+
<label igxLabel *ngIf="!labelDirective">Date</label>
27+
<ng-container ngProjectAs="[igxLabel]" *ngTemplateOutlet="labelTemplate"></ng-container>
2128
<igx-prefix (click)="onOpenClick($event)">
2229
<igx-icon>today</igx-icon>
2330
</igx-prefix>
24-
<label *ngIf="labelVisibility" igxLabel>{{label}}</label>
2531
<input
2632
class="igx-date-picker__input-date"
2733
igxInput

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

+22-29
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe('IgxDatePicker', () => {
5050
UIInteractions.clearOverlay();
5151
});
5252

53-
describe('Base Tests', () => {
53+
fdescribe('Base Tests', () => {
5454
// configureTestSuite();
5555
let fixture: ComponentFixture<IgxDatePickerTestComponent>;
5656
let datePicker: IgxDatePickerComponent;
@@ -149,42 +149,32 @@ describe('IgxDatePicker', () => {
149149
expect(datePicker.value).toEqual(date);
150150
});
151151

152-
it('When labelVisability is set to false the label should not be visible', () => {
153-
let label = fixture.debugElement.query(By.directive(IgxLabelDirective));
152+
fit('should display default and custom label', () => {
153+
const dom = fixture.debugElement;
154+
const testComponent = fixture.componentInstance;
154155

155-
expect(label.nativeElement.innerText).toBe(datePicker.label);
156+
let label = dom.query(By.directive(IgxLabelDirective)).nativeElement.innerText;
157+
expect(label).toEqual(testComponent.customLabel);
156158

157-
fixture.componentInstance.labelVisibility = false;
159+
testComponent.customLabelVisibility = false;
158160
fixture.detectChanges();
159161

160-
label = fixture.debugElement.query(By.directive(IgxLabelDirective));
161-
expect(label).toBeNull();
162-
});
163-
164-
it('When update label property it should reflect on the label text of the datepicker', () => {
165-
let label = fixture.debugElement.query(By.directive(IgxLabelDirective));
166-
expect(label.nativeElement.innerText).toEqual(datePicker.label);
162+
label = dom.query(By.directive(IgxLabelDirective)).nativeElement.innerText;
163+
expect(label).toEqual('Date');
167164

168-
const expectedResult = 'new label';
169-
datePicker.label = expectedResult;
165+
testComponent.customLabelVisibility = false;
170166
fixture.detectChanges();
167+
label = dom.query(By.directive(IgxLabelDirective)).nativeElement.innerText;
168+
expect(label).toEqual('Date');
171169

172-
label = fixture.debugElement.query(By.directive(IgxLabelDirective));
173-
expect(label.nativeElement.innerText).toEqual(expectedResult);
174-
});
175-
176-
it('Visualize the label of the datepicker when initially is hidden', () => {
177-
fixture.componentInstance.labelVisibility = false;
178170
fixture.detectChanges();
171+
label = dom.query(By.directive(IgxLabelDirective)).nativeElement.innerText;
172+
expect(label).toEqual('Date');
179173

180-
let label = fixture.debugElement.query(By.directive(IgxLabelDirective));
181-
expect(label).toBeNull();
182-
183-
fixture.componentInstance.labelVisibility = true;
174+
testComponent.customLabelVisibility = true;
184175
fixture.detectChanges();
185-
186-
label = fixture.debugElement.query(By.directive(IgxLabelDirective));
187-
expect(label).not.toBeNull();
176+
label = dom.query(By.directive(IgxLabelDirective)).nativeElement.innerText;
177+
expect(label).toEqual(testComponent.customLabel);
188178
});
189179

190180
it('Handling keyboard navigation with `space`(open) and `esc`(close) buttons', fakeAsync(() => {
@@ -1522,13 +1512,16 @@ export class IgxDatePickerWithWeekStartComponent {
15221512

15231513
@Component({
15241514
template: `
1525-
<igx-date-picker [labelVisibility]="labelVisibility"></igx-date-picker>
1515+
<igx-date-picker>
1516+
<label igxLabel *ngIf="customLabelVisibility">{{ customLabel }}</label>
1517+
</igx-date-picker>
15261518
`
15271519
})
15281520
export class IgxDatePickerTestComponent {
15291521
@ViewChild(IgxDatePickerComponent, { static: true }) public datePicker: IgxDatePickerComponent;
15301522

1531-
public labelVisibility = true;
1523+
public customLabelVisibility = true;
1524+
public customLabel = 'Custom label';
15321525
}
15331526

15341527
@Component({

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

+7-24
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import { IgxDatePickerTemplateDirective, IgxDatePickerActionsDirective } from '.
6161
import { IgxCalendarContainerComponent } from './calendar-container.component';
6262
import { InteractionMode } from '../core/enums';
6363
import { fadeIn, fadeOut } from '../animations/fade';
64+
import { IgxLabelDirective } from '../directives/label/label.directive';
6465

6566
let NEXT_ID = 0;
6667

@@ -153,28 +154,6 @@ const noop = () => { };
153154
})
154155
export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor,
155156
EditorProvider, OnInit, AfterViewInit, OnDestroy, AfterViewChecked {
156-
/**
157-
* Gets/Sets the `IgxDatePickerComponent` label.
158-
* @remarks
159-
* The default label is 'Date'.
160-
* @example
161-
* ```html
162-
* <igx-date-picker [label]="Calendar"></igx-date-picker>
163-
* ```
164-
*/
165-
@Input()
166-
public label = 'Date';
167-
168-
/**
169-
* Gets/Sets the `IgxDatePickerComponent` label visibility.
170-
* @remarks
171-
* By default the visibility is set to true.
172-
* @example
173-
* <igx-date-picker [labelVisibility]="false"></igx-date-picker>
174-
*/
175-
@Input()
176-
public labelVisibility = true;
177-
178157
/**
179158
* Gets/Sets the locales.
180159
* @remarks Default locale is en.
@@ -420,8 +399,6 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
420399
displayData: this.displayData,
421400
format: this.format,
422401
isSpinLoop: this.isSpinLoop,
423-
label: this.label,
424-
labelVisibility: this.labelVisibility,
425402
locale: this.locale,
426403
mask: this.mask,
427404
mode: this.mode,
@@ -620,6 +597,12 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
620597
@ViewChild('readOnlyDatePickerTemplate', { read: TemplateRef, static: true })
621598
protected readOnlyDatePickerTemplate: TemplateRef<any>;
622599

600+
/*
601+
* @hidden @internal
602+
*/
603+
@ContentChild(IgxLabelDirective)
604+
public labelDirective: IgxLabelDirective;
605+
623606
/*
624607
* @hidden
625608
*/

src/app/date-picker/date-picker.sample.html

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ <h4 class="sample-title">Default Date Picker - dialog mode</h4>
44
<p class="sample-description">Added buttons - today and cancel</p>
55
<div class="preview">
66
<igx-date-picker #datePicker cancelButtonLabel="cancel" todayButtonLabel="today">
7+
<label igxLabel>Custom Label</label>
78
</igx-date-picker>
89
<igx-buttongroup class="datepicker-actions">
910
<button igxButton igxRipple (click)="d()">Today</button>

0 commit comments

Comments
 (0)