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

Commit 1fb8ab5

Browse files
jelbournThomasBurleson
authored andcommitted
fix(datepicker): fix bad valid date check and resize-on-open.
Closes #4270.
1 parent a6c14b3 commit 1fb8ab5

File tree

6 files changed

+47
-5
lines changed

6 files changed

+47
-5
lines changed

src/components/datepicker/datePicker.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@
6060

6161
// This pane will be detached from here and re-attached to the document body.
6262
'<div class="md-datepicker-calendar-pane md-whiteframe-z1">' +
63-
'<div class="md-datepicker-input-mask"></div>' +
63+
'<div class="md-datepicker-input-mask">' +
64+
'<div class="md-datepicker-input-mask-opaque"></div>' +
65+
'</div>' +
6466
'<div class="md-datepicker-calendar">' +
6567
'<md-calendar role="dialog" aria-label="{{::ctrl.dateLocale.msgCalendar}}" ' +
6668
'ng-model="ctrl.date" ng-if="ctrl.isCalendarOpen"></md-calendar>' +
@@ -134,6 +136,12 @@
134136
/** @type {HTMLElement} Calendar icon button. */
135137
this.calendarButton = $element[0].querySelector('.md-datepicker-button');
136138

139+
/**
140+
* Element covering everything but the input in the top of the floating calendar pane.
141+
* @type {HTMLElement}
142+
*/
143+
this.inputMask = $element[0].querySelector('.md-datepicker-input-mask-opaque');
144+
137145
/** @final {!angular.JQLite} */
138146
this.$element = $element;
139147

@@ -262,7 +270,7 @@
262270

263271
Object.defineProperty(this, 'placeholder', {
264272
get: function() { return self.inputElement.placeholder; },
265-
set: function(value) { self.inputElement.placeholder = value; }
273+
set: function(value) { self.inputElement.placeholder = value || ''; }
266274
});
267275
};
268276

@@ -313,6 +321,12 @@
313321
calendarPane.style.top = (elementRect.top - bodyRect.top) + 'px';
314322
document.body.appendChild(this.calendarPane);
315323

324+
// The top of the calendar pane is a transparent box that shows the text input underneath.
325+
// Since the pane is flowing, though, the page underneath the pane *adjacent* to the input is
326+
// also shown unless we cover it up. The inputMask does this by filling up the remaining space
327+
// based on the width of the input.
328+
this.inputMask.style.left = elementRect.width + 'px';
329+
316330
// Add CSS class after one frame to trigger open animation.
317331
this.$$rAF(function() {
318332
calendarPane.classList.add('md-pane-open');

src/components/datepicker/datePicker.scss

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ $md-datepicker-button-gap: 12px; // Space between the text input and the calend
33
$md-datepicker-border-bottom-gap: 5px; // Space between input and the grey underline.
44
$md-datepicker-open-animation-duration: 0.2s;
55

6+
md-datepicker {
7+
// Don't let linebreaks happen between the open icon-button and the input.
8+
white-space: nowrap;
9+
}
610

711
// The calendar icon button used to open the calendar pane.
812
// Need absurd specificty to override md-button.md-icon-button.
@@ -62,12 +66,22 @@ $md-datepicker-open-animation-duration: 0.2s;
6266
.md-datepicker-input-mask {
6367
height: 40px;
6468
width: $md-calendar-width;
69+
position: relative;
6570

6671
background: transparent;
6772
pointer-events: none;
6873
cursor: text;
6974
}
7075

76+
.md-datepicker-input-mask-opaque {
77+
position: absolute;
78+
right: 0;
79+
left: 120px;
80+
background: white;
81+
82+
height: 100%;
83+
}
84+
7185
// The calendar portion of the floating pane (vs. the input mask).
7286
.md-datepicker-calendar {
7387
opacity: 0;
@@ -136,7 +150,6 @@ md-datepicker[disabled] {
136150
// Open state for all of the elements of the picker.
137151
.md-datepicker-open {
138152
.md-datepicker-input-container {
139-
min-width: $md-calendar-width;
140153
margin-left: -$md-datepicker-button-gap;
141154
border: none;
142155
}

src/components/datepicker/datePicker.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ describe('md-date-picker', function() {
4545
$timeout.flush();
4646

4747
expect(controller.calendarPane.offsetHeight).toBeGreaterThan(0);
48+
expect(controller.inputMask.style.left).toBe(controller.inputContainer.clientWidth + 'px');
4849

4950
// Click off of the calendar.
5051
document.body.click();

src/components/datepicker/dateUtil.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@
185185
* @return {boolean} Whether the date is a valid Date.
186186
*/
187187
function isValidDate(date) {
188-
return date !== null && date.getTime && !isNaN(date.getTime());
188+
return date != null && date.getTime && !isNaN(date.getTime());
189189
}
190190

191191
/**

src/components/datepicker/dateUtil.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,19 @@ describe('$$mdDateUtil', function() {
303303
expect(dayAtMidnight.getSeconds()).toBe(0);
304304
expect(dayAtMidnight.getMilliseconds()).toBe(0);
305305
});
306+
307+
it('should determine whether dates are valid', function() {
308+
expect(dateUtil.isValidDate(null)).toBeFalsy();
309+
expect(dateUtil.isValidDate(undefined)).toBeFalsy();
310+
expect(dateUtil.isValidDate('')).toBeFalsy();
311+
expect(dateUtil.isValidDate(0)).toBeFalsy();
312+
expect(dateUtil.isValidDate(NaN)).toBeFalsy();
313+
expect(dateUtil.isValidDate(123456789)).toBeFalsy();
314+
expect(dateUtil.isValidDate('123456789')).toBeFalsy();
315+
expect(dateUtil.isValidDate(new Date(''))).toBeFalsy();
316+
expect(dateUtil.isValidDate(new Date('Banjo'))).toBeFalsy();
317+
expect(dateUtil.isValidDate(new Date(NaN))).toBeFalsy();
318+
319+
expect(dateUtil.isValidDate(new Date())).toBe(true);
320+
});
306321
});

src/components/input/demoBasicUsage/script.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ angular
44
$scope.user = {
55
title: 'Developer',
66
email: 'ipsum@lorem.com',
7-
submissionDate: new Date(),
87
firstName: '',
98
lastName: '' ,
109
company: 'Google' ,

0 commit comments

Comments
 (0)