' +
- '
' +
- '
' +
- '' +
- '' +
+ '';
+
+ var triangleButton = (hiddenIcons === 'all' || hiddenIcons === 'triangle') ? '' :
+ '
' +
+ '' +
+ '';
+
+ return '' +
+ calendarButton +
+ '
' +
+ '' +
+ triangleButton +
+ '
' +
+
+ // This pane will be detached from here and re-attached to the document body.
+ '
' +
+ '
' +
-
- // This pane will be detached from here and re-attached to the document body.
- '
' +
- '
' +
- '
' +
- '' +
- '' +
- '
' +
- '
',
+ '
' +
+ '' +
+ '' +
+ '
' +
+ '
';
+ },
require: ['ngModel', 'mdDatepicker', '?^mdInputContainer'],
scope: {
minDate: '=mdMinDate',
maxDate: '=mdMaxDate',
placeholder: '@mdPlaceholder',
- dateFilter: '=mdDateFilter'
+ dateFilter: '=mdDateFilter',
+ isOpen: '=?mdIsOpen'
},
controller: DatePickerCtrl,
controllerAs: 'ctrl',
@@ -287,9 +304,22 @@
this.attachInteractionListeners();
var self = this;
+
$scope.$on('$destroy', function() {
self.detachCalendarPane();
});
+
+ if ($attrs.mdIsOpen) {
+ $scope.$watch('ctrl.isOpen', function(shouldBeOpen) {
+ if (shouldBeOpen) {
+ self.openCalendarPane({
+ target: self.inputElement
+ });
+ } else {
+ self.closeCalendarPane();
+ }
+ });
+ }
}
/**
@@ -396,7 +426,10 @@
DatePickerCtrl.prototype.setDisabled = function(isDisabled) {
this.isDisabled = isDisabled;
this.inputElement.disabled = isDisabled;
- this.calendarButton.disabled = isDisabled;
+
+ if (this.calendarButton) {
+ this.calendarButton.disabled = isDisabled;
+ }
};
/**
@@ -594,7 +627,7 @@
*/
DatePickerCtrl.prototype.openCalendarPane = function(event) {
if (!this.isCalendarOpen && !this.isDisabled) {
- this.isCalendarOpen = true;
+ this.isCalendarOpen = this.isOpen = true;
this.calendarPaneOpenedFrom = event.target;
// Because the calendar pane is attached directly to the body, it is possible that the
@@ -643,7 +676,7 @@
function detach() {
self.detachCalendarPane();
- self.isCalendarOpen = false;
+ self.isCalendarOpen = self.isOpen = false;
self.ngModelCtrl.$setTouched();
self.documentElement.off('click touchstart', self.bodyClickHandler);
diff --git a/src/components/datepicker/js/datepickerDirective.spec.js b/src/components/datepicker/js/datepickerDirective.spec.js
index e34da0055f1..483316da0e1 100644
--- a/src/components/datepicker/js/datepickerDirective.spec.js
+++ b/src/components/datepicker/js/datepickerDirective.spec.js
@@ -1,5 +1,5 @@
-describe('md-date-picker', function() {
+describe('md-datepicker', function() {
// When constructing a Date, the month is zero-based. This can be confusing, since people are
// used to seeing them one-based. So we create these aliases to make reading the tests easier.
var JAN = 0, FEB = 1, MAR = 2, APR = 3, MAY = 4, JUN = 5, JUL = 6, AUG = 7, SEP = 8, OCT = 9,
@@ -368,6 +368,29 @@ describe('md-date-picker', function() {
});
+ it('should open and close the floating calendar pane element via an expression on the scope', function() {
+ pageScope.isOpen = false;
+ createDatepickerInstance('
');
+
+ expect(controller.calendarPane.offsetHeight).toBe(0);
+ expect(controller.isCalendarOpen).toBe(false);
+
+ pageScope.$apply(function() {
+ pageScope.isOpen = true;
+ });
+
+ // Open the calendar externally
+ expect(controller.calendarPane.offsetHeight).toBeGreaterThan(0);
+ expect(controller.isCalendarOpen).toBe(true);
+
+ // Close the calendar via the datepicker
+ controller.$scope.$apply(function() {
+ controller.closeCalendarPane();
+ });
+ expect(pageScope.isOpen).toBe(false);
+ expect(controller.isCalendarOpen).toBe(false);
+ });
+
it('should adjust the position of the floating pane if it would go off-screen', function() {
// Absolutely position the picker near the edge of the screen.
var bodyRect = document.body.getBoundingClientRect();
@@ -541,4 +564,25 @@ describe('md-date-picker', function() {
controller.ngInputElement.triggerHandler('focus');
expect(document.querySelector('md-calendar')).toBeTruthy();
});
+
+ describe('hiding the icons', function() {
+ var calendarSelector = '.md-datepicker-button .md-datepicker-calendar-icon';
+ var triangleSelector = '.md-datepicker-triangle-button';
+
+ it('should be able to hide the calendar icon', function() {
+ createDatepickerInstance('
');
+ expect(element.querySelector(calendarSelector)).toBeNull();
+ });
+
+ it('should be able to hide the triangle icon', function() {
+ createDatepickerInstance('
');
+ expect(element.querySelector(triangleSelector)).toBeNull();
+ });
+
+ it('should be able to hide all icons', function() {
+ createDatepickerInstance('
');
+ expect(element.querySelector(calendarSelector)).toBeNull();
+ expect(element.querySelector(triangleSelector)).toBeNull();
+ });
+ });
});