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

Commit 56df8d5

Browse files
committed
feat(calendar): improve datepicker css
1 parent 1e28d52 commit 56df8d5

File tree

4 files changed

+64
-56
lines changed

4 files changed

+64
-56
lines changed

src/components/calendar/calendar.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@
4444
function calendarDirective() {
4545
return {
4646
template:
47-
'<div class="md-calendar-month-floating-label"></div>' +
4847
'<table class="md-calendar-day-header"><thead></thead></table>' +
4948
'<div class="md-calendar-scroll-mask">' +
5049
'<md-virtual-repeat-container class="md-calendar-scroller">' +
5150
'<table class="md-calendar">' +
5251
'<tbody md-virtual-repeat="i in ctrl.items" md-calendar-month ' +
5352
'md-month-offset="$index" class="md-calendar-month" aria-hidden="true" ' +
53+
'md-start-index="1000" ' +
5454
'md-item-size="' + TBODY_HEIGHT + '"></tbody>' +
5555
'</table>' +
5656
'</md-virtual-repeat-container>' +
5757
'</div>' +
58-
'<div aria-live="polite" class="md-visually-hidden"></div>',
58+
'<div aria-live="assertive" aria-atomic="true" class="md-visually-hidden"></div>',
5959
scope: {},
6060
restrict: 'E',
6161
require: ['ngModel', 'mdCalendar'],
@@ -186,7 +186,7 @@
186186

187187
// Do a one-time scroll to the selected date once the months have done their initial render.
188188
var off = $scope.$on('md-calendar-month-initial-render', function() {
189-
self.scrollToMonth(self.selectedDate);
189+
//self.scrollToMonth(self.selectedDate);
190190
off();
191191
});
192192

src/components/calendar/datePicker-theme.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.md-date-picker-root.md-THEME_NAME-theme {
1+
.md-datepicker-root.md-THEME_NAME-theme {
22
background: white;
33
&[disabled] {
44
background: '{{background-100}}';

src/components/calendar/datePicker.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
function datePickerDirective() {
2424
return {
2525
template:
26-
'<md-button class="md-date-picker-button md-icon-button" type="button" ' +
26+
'<md-button class="md-datepicker-button md-icon-button" type="button" ' +
2727
'ng-click="ctrl.openCalendarPane()">' +
28-
'<md-icon md-svg-icon="md-calendar"></md-icon>' +
28+
'<md-icon class="md-datepicker-calendar-icon" md-svg-icon="md-calendar"></md-icon>' +
2929
'</md-button>' +
3030
'<div class="md-datepicker-input-container">' +
3131
'<input class="md-datepicker-input">' +
@@ -38,13 +38,13 @@
3838

3939
// This pane (and its shadow) will be detached from here and re-attached to the
4040
// document body.
41-
'<div class="md-date-calendar-pane">' +
41+
'<div class="md-datepicker-calendar-pane">' +
4242
'<md-calendar ng-model="ctrl.date" ng-if="ctrl.isCalendarOpen"></md-calendar>' +
4343
'</div>' +
4444

4545
// We have a separate shadow element in order to wrap both the floating pane and the
4646
// inline input / trigger as one shadowed whole.
47-
'<div class="md-date-calendar-pane-shadow md-whiteframe-z1"></div>',
47+
'<div class="md-datepicker-calendar-pane-shadow md-whiteframe-z1"></div>',
4848
require: ['ngModel', 'mdDatePicker'],
4949
scope: {
5050
placeholder: '@mdPlaceholder'
@@ -99,13 +99,13 @@
9999
this.inputContainer = $element[0].querySelector('.md-datepicker-input-container');
100100

101101
/** @type {HTMLElement} Floating calendar pane. */
102-
this.calendarPane = $element[0].querySelector('.md-date-calendar-pane');
102+
this.calendarPane = $element[0].querySelector('.md-datepicker-calendar-pane');
103103

104104
/** @type {HTMLElement} Shadow for floating calendar pane and input trigger. */
105-
this.calendarShadow = $element[0].querySelector('.md-date-calendar-pane-shadow');
105+
this.calendarShadow = $element[0].querySelector('.md-datepicker-calendar-pane-shadow');
106106

107107
/** @type {HTMLElement} Calendar icon button. */
108-
this.calendarButton = $element[0].querySelector('.md-date-picker-button');
108+
this.calendarButton = $element[0].querySelector('.md-datepicker-button');
109109

110110
/** @final {!angular.JQLite} */
111111
this.$element = $element;
@@ -123,6 +123,8 @@
123123
/** @type {boolean} Whether the date-picker's calendar pane is open. */
124124
this.isCalendarOpen = false;
125125

126+
this.calendarPane.id = 'md-date-pane' + $mdUtil.nextUid();
127+
126128
/** Pre-bound click handler is saved so that the event listener can be removed. */
127129
this.bodyClickHandler = this.handleBodyClick.bind(this);
128130

@@ -232,12 +234,12 @@
232234
DatePickerCtrl.prototype.setDisabled = function(isDisabled) {
233235
this.isDisabled = isDisabled;
234236
this.inputElement.disabled = isDisabled;
237+
this.calendarButton.disabled = isDisabled;
235238
};
236239

237240
/** Position and attach the floating calendar to the document. */
238241
DatePickerCtrl.prototype.attachCalendarPane = function() {
239-
this.inputContainer.classList.add('md-open');
240-
this.calendarButton.classList.add('md-open');
242+
this.$element.addClass('md-datepicker-open');
241243

242244
var elementRect = this.inputContainer.getBoundingClientRect();
243245
var bodyRect = document.body.getBoundingClientRect();
@@ -249,7 +251,7 @@
249251
// Add shadow to the calendar pane only after the UI thread has reached idle, allowing the
250252
// content of the calender pane to be rendered.
251253
this.$timeout(function() {
252-
this.calendarShadow.style.top = (elementRect.top + window.pageYOffset) + 'px';
254+
this.calendarShadow.style.top = (elementRect.top - bodyRect.top) + 'px';
253255
this.calendarShadow.style.left = this.calendarPane.style.left;
254256
this.calendarShadow.style.height =
255257
(this.calendarPane.getBoundingClientRect().bottom - elementRect.top) + 'px';
@@ -259,8 +261,7 @@
259261

260262
/** Detach the floating calendar pane from the document. */
261263
DatePickerCtrl.prototype.detachCalendarPane = function() {
262-
this.inputContainer.classList.remove('md-open');
263-
this.calendarButton.classList.remove('md-open');
264+
this.$element.removeClass('md-datepicker-open');
264265

265266
// Use native DOM removal because we do not want any of the angular state of this element
266267
// to be disposed.
+47-40
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
$md-datepicker-button-size: 48px;
1+
// Space between the text input and the calendar-icon button.
22
$md-datepicker-button-gap: 12px;
33

44

55
// Mixin for a "flat" input that can be used for components that contain an input
66
// (datepicker, autocomplete).
7+
// TODO(jelbourn): actually use this w/ autocomplete.
78
@mixin md-flat-input() {
89
font-size: 14px;
910

@@ -20,21 +21,16 @@ $md-datepicker-button-gap: 12px;
2021

2122
// The calendar icon button used to open the calendar pane.
2223
// Need absurd specificty to override md-button.md-icon-button.
23-
.md-date-picker-button {
24+
.md-datepicker-button {
2425
display: inline-block;
2526
box-sizing: border-box;
2627
background: none;
27-
28-
&.md-open {
29-
fill: lightblue;
30-
}
3128
}
3229

3330
// The input into which the user can type the date.
3431
.md-datepicker-input {
3532
@include md-flat-input();
3633
width: 100%;
37-
line-height: 21px;
3834
}
3935

4036
// Container for the datepicker input.
@@ -46,28 +42,11 @@ $md-datepicker-button-gap: 12px;
4642
border-bottom: 1px solid #e0e0e0;
4743
width: 120px;
4844
margin-left: $md-datepicker-button-gap;
49-
50-
&.md-open {
51-
border: 1px solid #e0e0e0;
52-
border-bottom: none;
53-
min-width: $md-calendar-width;
54-
margin-left: -$md-datepicker-button-gap;
55-
56-
.md-datepicker-input {
57-
margin-left: 24px;
58-
//line-height: 40px;
59-
height: 40px;
60-
}
61-
62-
.md-datepicker-expand-triangle {
63-
display: none;
64-
}
65-
}
6645
}
6746

6847

6948
// Floating pane that contains the calendar at the bottom of the input.
70-
.md-date-calendar-pane {
49+
.md-datepicker-calendar-pane {
7150
position: absolute;
7251
top: 0;
7352
left: 0;
@@ -79,13 +58,32 @@ $md-datepicker-button-gap: 12px;
7958
}
8059

8160
// Shadow that wraps around both the floating calendar pane and the in-line input.
82-
.md-date-calendar-pane-shadow {
61+
.md-datepicker-calendar-pane-shadow {
8362
position: absolute;
8463
z-index: $z-index-datepicker-shadow;
8564
width: $md-calendar-width;
8665
}
8766

67+
// Down "disclosure" triangle/arrow indicating that the datepicker can be opened.
68+
// We can do this entirely with CSS without needing to load an icon.
69+
// See https://css-tricks.com/snippets/css/css-triangle/
70+
$md-date-arrow-size: 6px;
71+
.md-datepicker-expand-triangle {
72+
// Center the triangle inside of the button so that the
73+
// ink ripple origin looks correct.
74+
position: absolute;
75+
top: 50%;
76+
left: 50%;
77+
transform: translate(-50%, -50%);
78+
79+
width: 0;
80+
height: 0;
81+
border-left: $md-date-arrow-size solid transparent;
82+
border-right: $md-date-arrow-size solid transparent;
83+
border-top: $md-date-arrow-size solid rgba(black, 0.20);
84+
}
8885

86+
// Button containing the down "disclosure" triangle/arrow.
8987
.md-datepicker-triangle-button {
9088
position: absolute;
9189
right: 0;
@@ -97,23 +95,32 @@ $md-datepicker-button-gap: 12px;
9795
}
9896
}
9997

100-
// Need crazy specificity to override .md-button.md-icon-button
98+
// Need crazy specificity to override .md-button.md-icon-button.
99+
// Only apply this high specifiy to the property we need to override.
101100
.md-datepicker-triangle-button.md-button.md-icon-button {
102101
height: 100%;
103102
}
104103

105-
$md-date-arrow-size: 6px;
106-
.md-datepicker-expand-triangle {
107-
// Center the triangle inside of the button so that the
108-
// ink ripple origin looks correct.
109-
position: absolute;
110-
top: 50%;
111-
left: 50%;
112-
transform: translate(-50%, -50%);
113104

114-
width: 0;
115-
height: 0;
116-
border-left: $md-date-arrow-size solid transparent;
117-
border-right: $md-date-arrow-size solid transparent;
118-
border-top: $md-date-arrow-size solid rgba(black, 0.20);
105+
// Open state for all of the elements of the picker.
106+
.md-datepicker-open {
107+
.md-datepicker-input-container {
108+
border: 1px solid #e0e0e0;
109+
border-bottom: none;
110+
min-width: $md-calendar-width;
111+
margin-left: -$md-datepicker-button-gap;
112+
}
113+
114+
.md-datepicker-input {
115+
margin-left: 24px;
116+
height: 40px;
117+
}
118+
119+
.md-datepicker-expand-triangle {
120+
display: none;
121+
}
122+
123+
.md-datepicker-calendar-icon {
124+
fill: #2196f3;
125+
}
119126
}

0 commit comments

Comments
 (0)