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

Commit 5004a2a

Browse files
committed
fix(datepicker): throw error if inside md-input-container. For #5055
1 parent 06c60af commit 5004a2a

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/components/datepicker/datePicker.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
'</md-calendar>' +
8080
'</div>' +
8181
'</div>',
82-
require: ['ngModel', 'mdDatepicker'],
82+
require: ['ngModel', 'mdDatepicker', '?^mdInputContainer'],
8383
scope: {
8484
minDate: '=mdMinDate',
8585
maxDate: '=mdMaxDate',
@@ -92,6 +92,11 @@
9292
var ngModelCtrl = controllers[0];
9393
var mdDatePickerCtrl = controllers[1];
9494

95+
var mdInputContainer = controllers[2];
96+
if (mdInputContainer) {
97+
throw Error('md-datepicker should not be placed inside md-input-container.');
98+
}
99+
95100
mdDatePickerCtrl.configureNgModel(ngModelCtrl);
96101
}
97102
};

src/components/datepicker/datePicker.spec.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ describe('md-date-picker', function() {
1919
'ng-disabled="isDisabled">' +
2020
'</md-datepicker>';
2121

22-
beforeEach(module('material.components.datepicker', 'ngAnimateMock'));
22+
var fakeInputModule = angular.module('fakeInputModule', [])
23+
.directive('mdInputContainer', function() {
24+
return {controller: angular.noop};
25+
});
26+
27+
beforeEach(module('material.components.datepicker', 'ngAnimateMock', 'fakeInputModule'));
2328

2429
beforeEach(inject(function($rootScope, $injector) {
2530
$compile = $injector.get('$compile');
@@ -94,6 +99,17 @@ describe('md-date-picker', function() {
9499
expect(controller.inputElement.placeholder).toBe('Fancy new placeholder');
95100
});
96101

102+
it('should throw an error when inside of md-input-container', function() {
103+
var template =
104+
'<md-input-container>' +
105+
'<md-datepicker ng-model="myDate"></md-datepicker>' +
106+
'</md-input-container>';
107+
108+
expect(function() {
109+
$compile(template)(pageScope);
110+
}).toThrowError('md-datepicker should not be placed inside md-input-container.');
111+
});
112+
97113
describe('ngMessages suport', function() {
98114
it('should set the `required` $error flag', function() {
99115
pageScope.isRequired = true;

0 commit comments

Comments
 (0)