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

Commit e4693ce

Browse files
committed
fix(datepicker): remove negative margin if triangle icon is disabled
Usually the datepicker uses padding and a negative margin to prevent clicks on the triangle button from shifting the entire element, which is unnecessary in the case where the triangle icon is disabled. This change removes the negative margin and padding in that case. Fixes #9850.
1 parent 70cecda commit e4693ce

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/components/datepicker/datePicker.scss

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ md-datepicker {
1212
// Don't let linebreaks happen between the open icon-button and the input.
1313
white-space: nowrap;
1414
overflow: hidden;
15-
16-
// Leave room for the down-triangle button to "overflow" it's parent without modifying scrollLeft.
17-
// This prevents the element from shifting right when opening via the triangle button.
18-
@include rtl-prop(padding-right, padding-left, $md-datepicker-triangle-button-width / 2, 0);
19-
@include rtl-prop(margin-right, margin-left, -$md-datepicker-triangle-button-width / 2, auto);
20-
2115
vertical-align: middle;
2216
}
2317

@@ -95,6 +89,12 @@ md-datepicker {
9589
}
9690
}
9791

92+
._md-datepicker-has-triangle-icon {
93+
// Leave room for the down-triangle button to "overflow" it's parent without modifying scrollLeft.
94+
// This prevents the element from shifting right when opening via the triangle button.
95+
@include rtl-prop(padding-right, padding-left, $md-datepicker-triangle-button-width / 2, 0);
96+
@include rtl-prop(margin-right, margin-left, -$md-datepicker-triangle-button-width / 2, auto);
97+
}
9898

9999
// Container for the datepicker input.
100100
.md-datepicker-input-container {

src/components/datepicker/js/datepickerDirective.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,20 @@
7878
'md-svg-src="' + $$mdSvgRegistry.mdCalendar + '"></md-icon>' +
7979
'</md-button>';
8080

81-
var triangleButton = (hiddenIcons === 'all' || hiddenIcons === 'triangle') ? '' :
82-
'<md-button type="button" md-no-ink ' +
81+
var triangleButton = '';
82+
83+
if (hiddenIcons !== 'all' && hiddenIcons !== 'triangle') {
84+
triangleButton = '' +
85+
'<md-button type="button" md-no-ink ' +
8386
'class="md-datepicker-triangle-button md-icon-button" ' +
8487
'ng-click="ctrl.openCalendarPane($event)" ' +
8588
'aria-label="{{::ctrl.locale.msgOpenCalendar}}">' +
8689
'<div class="md-datepicker-expand-triangle"></div>' +
8790
'</md-button>';
8891

92+
tElement.addClass(HAS_TRIANGLE_ICON_CLASS);
93+
}
94+
8995
return calendarButton +
9096
'<div class="md-datepicker-input-container" ng-class="{\'md-datepicker-focused\': ctrl.isFocused}">' +
9197
'<input ' +
@@ -156,7 +162,7 @@
156162
mdInputContainer.input = element;
157163
mdInputContainer.element
158164
.addClass(INPUT_CONTAINER_CLASS)
159-
.toggleClass(HAS_ICON_CLASS, attr.mdHideIcons !== 'calendar' && attr.mdHideIcons !== 'all');
165+
.toggleClass(HAS_CALENDAR_ICON_CLASS, attr.mdHideIcons !== 'calendar' && attr.mdHideIcons !== 'all');
160166

161167
if (!mdInputContainer.label) {
162168
$mdAria.expect(element, 'aria-label', attr.mdPlaceholder);
@@ -197,7 +203,10 @@
197203
var INPUT_CONTAINER_CLASS = '_md-datepicker-floating-label';
198204

199205
/** Class to be applied when the calendar icon is enabled. */
200-
var HAS_ICON_CLASS = '_md-datepicker-has-calendar-icon';
206+
var HAS_CALENDAR_ICON_CLASS = '_md-datepicker-has-calendar-icon';
207+
208+
/** Class to be applied when the triangle icon is enabled. */
209+
var HAS_TRIANGLE_ICON_CLASS = '_md-datepicker-has-triangle-icon';
201210

202211
/** Default time in ms to debounce input event by. */
203212
var DEFAULT_DEBOUNCE_INTERVAL = 500;

0 commit comments

Comments
 (0)