|
58 | 58 | minDate: '=mdMinDate', |
59 | 59 | maxDate: '=mdMaxDate', |
60 | 60 | dateFilter: '=mdDateFilter', |
61 | | - _currentView: '@mdCurrentView' |
| 61 | + _currentView: '@mdCurrentView', |
| 62 | + |
| 63 | + // private way of passing in the panel from the datepicker |
| 64 | + _panelRef: '=mdPanelRef' |
62 | 65 | }, |
63 | 66 | require: ['ngModel', 'mdCalendar'], |
64 | 67 | controller: CalendarCtrl, |
|
197 | 200 |
|
198 | 201 | var boundKeyHandler = angular.bind(this, this.handleKeyEvent); |
199 | 202 |
|
200 | | - // Bind the keydown handler to the body, in order to handle cases where the focused |
201 | | - // element gets removed from the DOM and stops propagating click events. |
202 | | - angular.element(document.body).on('keydown', boundKeyHandler); |
| 203 | + if (this._panelRef) { |
| 204 | + // Bind the keydown handler to the body, in order to handle cases where the focused |
| 205 | + // element gets removed from the DOM and stops propagating key events. |
| 206 | + angular.element(document.body).on('keydown', boundKeyHandler); |
203 | 207 |
|
204 | | - $scope.$on('$destroy', function() { |
205 | | - angular.element(document.body).off('keydown', boundKeyHandler); |
206 | | - }); |
| 208 | + $scope.$on('$destroy', function() { |
| 209 | + angular.element(document.body).off('keydown', boundKeyHandler); |
| 210 | + }); |
| 211 | + } else { |
| 212 | + // If the calendar on it's own, it shouldn't bind global key handlers. |
| 213 | + $element.on('keydown', boundKeyHandler); |
| 214 | + } |
207 | 215 |
|
208 | 216 | if (this.minDate && this.minDate > $mdDateLocale.firstRenderableDate) { |
209 | 217 | this.firstRenderableDate = this.minDate; |
|
345 | 353 | CalendarCtrl.prototype.handleKeyEvent = function(event) { |
346 | 354 | var self = this; |
347 | 355 |
|
348 | | - this.$scope.$apply(function() { |
349 | | - // Capture escape and emit back up so that a wrapping component |
350 | | - // (such as a date-picker) can decide to close. |
351 | | - if (event.which == self.keyCode.ESCAPE || event.which == self.keyCode.TAB) { |
352 | | - self.$scope.$emit('md-calendar-close'); |
353 | | - |
354 | | - if (event.which == self.keyCode.TAB) { |
| 356 | + if (!this._panelRef || this._panelRef.isAttached) { |
| 357 | + this.$scope.$apply(function() { |
| 358 | + // Capture tabbing and emit back up so that a wrapping component |
| 359 | + // (such as a date-picker) can decide to close. |
| 360 | + if (event.which === self.keyCode.TAB) { |
| 361 | + self.$scope.$emit('md-calendar-close'); |
355 | 362 | event.preventDefault(); |
| 363 | + return; |
356 | 364 | } |
357 | 365 |
|
358 | | - return; |
359 | | - } |
360 | | - |
361 | | - // Broadcast the action that any child controllers should take. |
362 | | - var action = self.getActionFromKeyEvent(event); |
363 | | - if (action) { |
364 | | - event.preventDefault(); |
365 | | - event.stopPropagation(); |
366 | | - self.$scope.$broadcast('md-calendar-parent-action', action); |
367 | | - } |
368 | | - }); |
| 366 | + // Broadcast the action that any child controllers should take. |
| 367 | + var action = self.getActionFromKeyEvent(event); |
| 368 | + if (action) { |
| 369 | + event.preventDefault(); |
| 370 | + event.stopPropagation(); |
| 371 | + self.$scope.$broadcast('md-calendar-parent-action', action); |
| 372 | + } |
| 373 | + }); |
| 374 | + } |
369 | 375 | }; |
370 | 376 |
|
371 | 377 | /** |
|
0 commit comments