Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 8826412

Browse files
jelbournThomasBurleson
authored andcommitted
fix(datepicker): ngModel updates for empty input.
Fixes #4643. Closes #4648.
1 parent bc3d4db commit 8826412

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

src/components/datepicker/datePicker-theme.scss

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ md-datepicker.md-THEME_NAME-theme {
77
.md-THEME_NAME-theme {
88

99
.md-datepicker-input {
10+
@include input-placeholder-color('{{foreground-3}}');
1011
color: '{{background-contrast}}';
1112
background: '{{background-color}}';
1213
}

src/components/datepicker/datePicker.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,11 @@
331331
var parsedDate = this.dateLocale.parseDate(inputString);
332332
this.dateUtil.setDateTimeToMidnight(parsedDate);
333333

334-
if (this.dateUtil.isValidDate(parsedDate) &&
334+
if (inputString === '') {
335+
this.ngModelCtrl.$setViewValue(null);
336+
this.date = null;
337+
this.inputContainer.classList.remove(INVALID_CLASS);
338+
} else if (this.dateUtil.isValidDate(parsedDate) &&
335339
this.dateLocale.isDateComplete(inputString) &&
336340
this.dateUtil.isDateWithinRange(parsedDate, this.minDate, this.maxDate)) {
337341
this.ngModelCtrl.$setViewValue(parsedDate);

src/components/datepicker/datePicker.scss

+3-3
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ md-datepicker[disabled] {
174174
// view while the pane is opening. This is done as a cue to users that the calendar is scrollable.
175175
.md-datepicker-calendar-pane {
176176
.md-calendar {
177-
transform: translateY(150px);
178-
transition: transform 0.4s $swift-ease-out-timing-function;
179-
transition-delay: 0.1s;
177+
transform: translateY(-85px);
178+
transition: transform 0.65s $swift-ease-out-timing-function;
179+
transition-delay: 0.125s;
180180
}
181181

182182
&.md-pane-open .md-calendar {

src/components/datepicker/datePicker.spec.js

+8
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ describe('md-date-picker', function() {
5050
expect(controller.inputElement.value).toBe(dateLocale.formatDate(initialDate));
5151
});
5252

53+
it('should set the ngModel value to null when the text input is emptied', function() {
54+
controller.inputElement.value = '';
55+
controller.ngInputElement.triggerHandler('input');
56+
$timeout.flush();
57+
58+
expect(pageScope.myDate).toBeNull();
59+
});
60+
5361
it('should open and close the floating calendar pane element', function() {
5462
// We can asset that the calendarPane is in the DOM by checking if it has a height.
5563
expect(controller.calendarPane.offsetHeight).toBe(0);

src/components/datepicker/demoBasicUsage/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ <h4>Standard date-picker</h4>
55
<md-datepicker ng-model="myDate" md-placeholder="Enter date"></md-datepicker>
66

77
<h4>Disabled date-picker</h4>
8-
<md-datepicker ng-model="myDate" placeholder="Enter date" disabled></md-datepicker>
8+
<md-datepicker ng-model="myDate" md-placeholder="Enter date" disabled></md-datepicker>
99

1010
<h4>Date-picker with min date and max date</h4>
11-
<md-datepicker ng-model="myDate" placeholder="Enter date"
11+
<md-datepicker ng-model="myDate" md-placeholder="Enter date"
1212
md-min-date="minDate" md-max-date="maxDate"></md-datepicker>
1313
</md-content>
1414
</div>

0 commit comments

Comments
 (0)