Skip to content

Commit 52a6d41

Browse files
Olivier Goguelbrandyscarney
authored andcommitted
feat(datetime): add placeholder attribute
fixes #7966
1 parent 6a0c92c commit 52a6d41

File tree

5 files changed

+36
-1
lines changed

5 files changed

+36
-1
lines changed

src/components/datetime/datetime.ios.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ $datetime-ios-padding-bottom: $item-ios-padding-bottom !default;
1515
/// @prop - Padding left of the DateTime component
1616
$datetime-ios-padding-left: $item-ios-padding-left !default;
1717

18+
/// @prop - Color of the DateTime placeholder
19+
$datetime-ios-placeholder-color: #999 !default;
20+
1821

1922
.datetime-ios {
2023
padding: $datetime-ios-padding-top $datetime-ios-padding-right $datetime-ios-padding-bottom $datetime-ios-padding-left;
2124
}
25+
26+
.datetime-ios .datetime-placeholder {
27+
color: $datetime-ios-placeholder-color;
28+
}

src/components/datetime/datetime.md.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ $datetime-md-padding-bottom: $item-md-padding-bottom !default;
1515
/// @prop - Padding left of the DateTime component
1616
$datetime-md-padding-left: $item-md-padding-left !default;
1717

18+
/// @prop - Color of the DateTime placeholder
19+
$datetime-md-placeholder-color: #999 !default;
20+
1821

1922
.datetime-md {
2023
padding: $datetime-md-padding-top $datetime-md-padding-right $datetime-md-padding-bottom $datetime-md-padding-left;
2124
}
25+
26+
.datetime-md .datetime-placeholder {
27+
color: $datetime-md-placeholder-color;
28+
}

src/components/datetime/datetime.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ export const DATETIME_VALUE_ACCESSOR: any = {
251251
@Component({
252252
selector: 'ion-datetime',
253253
template:
254-
'<div class="datetime-text">{{_text}}</div>' +
254+
'<div *ngIf="!_text" class="datetime-text datetime-placeholder">{{placeholder}}</div>' +
255+
'<div *ngIf="_text" class="datetime-text">{{_text}}</div>' +
255256
'<button aria-haspopup="true" ' +
256257
'type="button" ' +
257258
'[id]="id" ' +
@@ -407,6 +408,12 @@ export class DateTime extends Ion implements AfterContentInit, ControlValueAcces
407408
*/
408409
@Input() pickerOptions: any = {};
409410

411+
/**
412+
* @input {string} The text to display when there's no date selected yet.
413+
* Using lowercase to match the input attribute
414+
*/
415+
@Input() placeholder: string = '';
416+
410417
/**
411418
* @input {string} The mode determines which platform styles to use.
412419
* Possible values are: `"ios"`, `"md"`, or `"wp"`.

src/components/datetime/datetime.wp.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ $datetime-wp-border-width: 2px !default;
2424
/// @prop - Border color of the DateTime component
2525
$datetime-wp-border-color: $input-wp-border-color !default;
2626

27+
/// @prop - Color of the DateTime placeholder
28+
$datetime-wp-placeholder-color: $input-wp-border-color !default;
29+
30+
2731
.datetime-wp {
2832
padding: $datetime-wp-padding-top $datetime-wp-padding-right $datetime-wp-padding-bottom $datetime-wp-padding-left;
2933

@@ -42,3 +46,8 @@ $datetime-wp-border-color: $input-wp-border-color !default;
4246
.item-datetime .datetime-wp ion-label[floating] {
4347
transform: translate3d(8px, 41px, 0);
4448
}
49+
50+
.datetime-wp .datetime-placeholder {
51+
color: $datetime-wp-placeholder-color;
52+
}
53+

src/components/datetime/test/basic/main.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
<ion-datetime displayFormat="MMMM" [(ngModel)]="monthOnly"></ion-datetime>
1515
</ion-item>
1616

17+
<ion-item>
18+
<ion-label>MM DD YY</ion-label>
19+
<ion-datetime displayFormat="MM DD YY" [(ngModel)]="placeholderDate" placeholder="Select Date"></ion-datetime>
20+
</ion-item>
21+
1722
<ion-item>
1823
<ion-label>YYYY</ion-label>
1924
<ion-datetime displayFormat="YYYY" min="1981" max="2002" [(ngModel)]="wwwInvented"></ion-datetime>

0 commit comments

Comments
 (0)