Skip to content

Commit 6c66976

Browse files
authored
feat(date-picker): content project the label #8086 (#8088)
1 parent c9276f1 commit 6c66976

File tree

6 files changed

+102
-9
lines changed

6 files changed

+102
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ All notable changes for each version of this project will be documented in this
99
- **Behavioral Change** - The styling of the input group is now dictated by the theme being used. The remaining `types` - `line`, `border`, and `box` will only have effect on the styling when used with the `material` theme. The `search` type will affect styling when used with all themes. Changing the theme at runtime will not change the styling of the input group, a page refresh is required.
1010
- `IgxSelect`
1111
- Added `aria-labelledby` property for the items list container(marked as `role="listbox"`). This will ensure the users of assistive technologies will also know what the list items container is used for, upon opening.
12+
- `IgxDatePicker`
13+
- **Breaking Change** - Deprecated the `label` and `labelVisibility` properties.
1214

1315
### New Features
1416
- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`
@@ -17,6 +19,8 @@ All notable changes for each version of this project will be documented in this
1719
- Allows for setting an input group `type` on a global level, so all input-group instances, including components using such an instance as a template will have their input group type set to the one specified by the token. It can be overridden on a component level by explicitly setting a `type`.
1820
- ` IgxExcelExporterService`
1921
- Added `worksheetName` property to the `IgxExcelExporterOptions`, that allows setting the name of the worksheet.
22+
- `IgxDatePicker`
23+
- The `labelVisibility` and the `label` property have been deprecated and now a custom label is set by nesting a <label igxLabel></label> inside the <igx-date-picker><igx-date-picker> tags.
2024
- `IgxTimePicker`
2125
- Added a custom label functionality.
2226
- `IgxCalendar` and `IgxDatePicker` - new `showWeekNumbers` input, that allows showing of the week number at left side of content area.

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ DatePicker with cancel and today buttons
4141
</igx-date-picker>
4242
```
4343

44+
The DatePicker's custom label can be set in the way shown below. If `labelVisibility` is set to `false` and a custom label is not used, a default one will be set.
45+
````html
46+
<igx-date-picker>
47+
<label igxLabel>Custom label</label>
48+
</igx-date-picker>
49+
4450
You have also ability to disable the datePicker
4551
```html
4652
<igx-date-picker [disabled]="false">
@@ -123,8 +129,8 @@ The DatePicker action buttons could be retemplated.
123129
| `weekStart`| `Number \| WEEKDAYS` | Sets on which day will the week start. |
124130
| `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. |
125131
| `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. |
132+
| `label` | `string` | Deprecated. Configure the input label text. |
133+
| `labelVisibility` | `string` | Deprecated. Configure the input label text visibility. |
128134
| `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. |
129135
| `mask` | `string` | Configure the date editor mask. Accepts the d, M and y symbols as mask - for example dd-MM-y. |
130136
| `disabledDates` | `DateRangeDescriptor[]` | Configure the disabled dates. |
@@ -154,4 +160,4 @@ The DatePicker action buttons could be retemplated.
154160
| `selectDate` | `date: Date` | `void` | Change the calendar selection. Calling this method will emit the `onSelection` event. |
155161
| `deselectDate` | `void` | Deselects the calendar date and clear input field value. |
156162
| `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. |
163+
| `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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
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&&!labelVisibility">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>
12+
<label *ngIf="labelVisibility&&!labelDirective" igxLabel>{{label}}</label>
713
<input
814
class="igx-date-picker__input-date"
915
igxInput
@@ -18,10 +24,12 @@
1824

1925
<ng-template #editableDatePickerTemplate>
2026
<igx-input-group #editableInputGroup>
27+
<label igxLabel *ngIf="!labelDirective&&!labelVisibility">Date</label>
28+
<ng-container ngProjectAs="[igxLabel]" *ngTemplateOutlet="labelTemplate"></ng-container>
2129
<igx-prefix (click)="onOpenClick($event)">
2230
<igx-icon>today</igx-icon>
2331
</igx-prefix>
24-
<label *ngIf="labelVisibility" igxLabel>{{label}}</label>
32+
<label *ngIf="labelVisibility&&!labelDirective" igxLabel>{{label}}</label>
2533
<input
2634
class="igx-date-picker__input-date"
2735
igxInput

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

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe('IgxDatePicker', () => {
2727
TestBed.configureTestingModule({
2828
declarations: [
2929
IgxDatePickerTestComponent,
30+
IgxDatePickerProjectedLabelTestComponent,
3031
IgxDatePickerWithWeekStartComponent,
3132
IgxDatePickerWithCustomFormatterComponent,
3233
IgxDatePickerWithPassedDateComponent,
@@ -149,7 +150,7 @@ describe('IgxDatePicker', () => {
149150
expect(datePicker.value).toEqual(date);
150151
});
151152

152-
it('When labelVisability is set to false the label should not be visible', () => {
153+
it('When labelVisibility is set to false the label should not be visible', () => {
153154
let label = fixture.debugElement.query(By.directive(IgxLabelDirective));
154155

155156
expect(label.nativeElement.innerText).toBe(datePicker.label);
@@ -158,7 +159,7 @@ describe('IgxDatePicker', () => {
158159
fixture.detectChanges();
159160

160161
label = fixture.debugElement.query(By.directive(IgxLabelDirective));
161-
expect(label).toBeNull();
162+
expect(label.nativeElement.innerText).toBe('Date');
162163
});
163164

164165
it('When update label property it should reflect on the label text of the datepicker', () => {
@@ -178,7 +179,7 @@ describe('IgxDatePicker', () => {
178179
fixture.detectChanges();
179180

180181
let label = fixture.debugElement.query(By.directive(IgxLabelDirective));
181-
expect(label).toBeNull();
182+
expect(label.nativeElement.innerText).toBe('Date');
182183

183184
fixture.componentInstance.labelVisibility = true;
184185
fixture.detectChanges();
@@ -187,6 +188,35 @@ describe('IgxDatePicker', () => {
187188
expect(label).not.toBeNull();
188189
});
189190

191+
it('should display default and custom label', () => {
192+
const fixtureProjectedLabel = TestBed.createComponent(IgxDatePickerProjectedLabelTestComponent);
193+
const dom = fixtureProjectedLabel.debugElement;
194+
const testComponent = fixtureProjectedLabel.componentInstance;
195+
fixtureProjectedLabel.detectChanges();
196+
197+
let label = dom.query(By.directive(IgxLabelDirective)).nativeElement.innerText;
198+
expect(label).toEqual(testComponent.customLabel);
199+
200+
testComponent.customLabelVisibility = false;
201+
fixtureProjectedLabel.detectChanges();
202+
203+
label = dom.query(By.directive(IgxLabelDirective)).nativeElement.innerText;
204+
expect(label).toEqual('Date');
205+
206+
testComponent.labelVisibility = false;
207+
fixtureProjectedLabel.detectChanges();
208+
testComponent.customLabelVisibility = false;
209+
fixtureProjectedLabel.detectChanges();
210+
label = dom.query(By.directive(IgxLabelDirective)).nativeElement.innerText;
211+
fixtureProjectedLabel.detectChanges();
212+
expect(label).toEqual('Date');
213+
214+
testComponent.customLabelVisibility = true;
215+
fixtureProjectedLabel.detectChanges();
216+
label = dom.query(By.directive(IgxLabelDirective)).nativeElement.innerText;
217+
expect(label).toEqual(testComponent.customLabel);
218+
});
219+
190220
it('Handling keyboard navigation with `space`(open) and `esc`(close) buttons', fakeAsync(() => {
191221
const datePickerDom = fixture.debugElement.query(By.css('igx-date-picker'));
192222
UIInteractions.triggerKeyDownEvtUponElem('space', datePickerDom.nativeElement, false);
@@ -1520,6 +1550,21 @@ export class IgxDatePickerWithWeekStartComponent {
15201550
@ViewChild(IgxDatePickerComponent, { static: true }) public datePicker: IgxDatePickerComponent;
15211551
}
15221552

1553+
@Component({
1554+
template: `
1555+
<igx-date-picker [labelVisibility]="labelVisibility">
1556+
<label igxLabel *ngIf="customLabelVisibility">{{ customLabel }}</label>
1557+
</igx-date-picker>
1558+
`
1559+
})
1560+
export class IgxDatePickerProjectedLabelTestComponent {
1561+
@ViewChild(IgxDatePickerComponent, { static: true }) public datePicker: IgxDatePickerComponent;
1562+
1563+
public customLabelVisibility = true;
1564+
public customLabel = 'Custom label';
1565+
public labelVisibility = true;
1566+
}
1567+
15231568
@Component({
15241569
template: `
15251570
<igx-date-picker [labelVisibility]="labelVisibility"></igx-date-picker>
@@ -1530,7 +1575,6 @@ export class IgxDatePickerTestComponent {
15301575

15311576
public labelVisibility = true;
15321577
}
1533-
15341578
@Component({
15351579
template: `
15361580
<igx-date-picker [value]="date" [formatOptions]="formatOptions"></igx-date-picker>

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ 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';
65+
import { DeprecateProperty } from '../core/deprecateDecorators';
6466

6567
let NEXT_ID = 0;
6668

@@ -161,7 +163,18 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
161163
* ```html
162164
* <igx-date-picker [label]="Calendar"></igx-date-picker>
163165
* ```
166+
* @deprecated Use igxLabel inside the date picker to change the label:
167+
* ````html
168+
* <igx-date-picker>
169+
* <label igxLabel>Custom label</label>
170+
* </igx-date-picker>
171+
* ````
172+
* to set a custom label.
164173
*/
174+
@DeprecateProperty(`Use igxLabel inside the date picker to change the label:
175+
<igx-date-picker>
176+
<label igxLabel>Custom label</label>
177+
</igx-date-picker> `)
165178
@Input()
166179
public label = 'Date';
167180

@@ -171,7 +184,18 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
171184
* By default the visibility is set to true.
172185
* @example
173186
* <igx-date-picker [labelVisibility]="false"></igx-date-picker>
187+
* @deprecated Use
188+
* ````html
189+
* <igx-date-picker>
190+
* <label igxLabel>Custom label</label>
191+
* </igx-date-picker>
192+
* ````
193+
* to set a custom label.
174194
*/
195+
@DeprecateProperty(`Deprecated. Use
196+
<igx-date-picker>
197+
<label igxLabel>Custom label</label>
198+
</igx-date-picker> to set a label.` )
175199
@Input()
176200
public labelVisibility = true;
177201

@@ -631,6 +655,12 @@ export class IgxDatePickerComponent implements IDatePicker, ControlValueAccessor
631655
@ViewChild('readOnlyDatePickerTemplate', { read: TemplateRef, static: true })
632656
protected readOnlyDatePickerTemplate: TemplateRef<any>;
633657

658+
/*
659+
* @hidden @internal
660+
*/
661+
@ContentChild(IgxLabelDirective)
662+
public labelDirective: IgxLabelDirective;
663+
634664
/*
635665
* @hidden
636666
*/

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

Lines changed: 1 addition & 0 deletions
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 [showWeekNumbers]="true" 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)