|
107 | 107 | * Controller for the mdCalendar component.
|
108 | 108 | * @ngInject @constructor
|
109 | 109 | */
|
110 |
| - function CalendarCtrl($element, $scope, $$mdDateUtil, $mdUtil, |
111 |
| - $mdConstant, $mdTheming, $$rAF, $attrs, $mdDateLocale, $filter) { |
112 |
| - |
| 110 | + function CalendarCtrl($element, $scope, $$mdDateUtil, $mdUtil, $mdConstant, $mdTheming, $$rAF, |
| 111 | + $attrs, $mdDateLocale, $filter, $document) { |
113 | 112 | $mdTheming($element);
|
114 | 113 |
|
115 | 114 | /**
|
|
229 | 228 | */
|
230 | 229 | this.scrollbarWidth = 0;
|
231 | 230 |
|
| 231 | + /** |
| 232 | + * @type {boolean} set to true if the calendar is being used "standalone" (outside of a |
| 233 | + * md-datepicker). |
| 234 | + */ |
| 235 | + this.standaloneMode = false; |
| 236 | + |
232 | 237 | // Unless the user specifies so, the calendar should not be a tab stop.
|
233 | 238 | // This is necessary because ngAria might add a tabindex to anything with an ng-model
|
234 | 239 | // (based on whether or not the user has turned that particular feature on/off).
|
|
245 | 250 |
|
246 | 251 | var handleKeyElement;
|
247 | 252 | if ($element.parent().hasClass('md-datepicker-calendar')) {
|
248 |
| - handleKeyElement = angular.element(document.body); |
| 253 | + handleKeyElement = angular.element($document[0].body); |
249 | 254 | } else {
|
| 255 | + this.standaloneMode = true; |
250 | 256 | handleKeyElement = $element;
|
251 | 257 | }
|
252 | 258 |
|
|
445 | 451 | * Normalizes the key event into an action name. The action will be broadcast
|
446 | 452 | * to the child controllers.
|
447 | 453 | * @param {KeyboardEvent} event
|
448 |
| - * @returns {String} The action that should be taken, or null if the key |
449 |
| - * does not match a calendar shortcut. |
| 454 | + * @returns {string} The action that should be taken, or null if the key |
| 455 | + * does not match a calendar shortcut. |
450 | 456 | */
|
451 | 457 | CalendarCtrl.prototype.getActionFromKeyEvent = function(event) {
|
452 | 458 | var keyCode = this.keyCode;
|
|
471 | 477 | };
|
472 | 478 |
|
473 | 479 | /**
|
474 |
| - * Handles a key event in the calendar with the appropriate action. The action will either |
475 |
| - * be to select the focused date or to navigate to focus a new date. |
| 480 | + * Handles a key event in the calendar with the appropriate action. |
| 481 | + * The action will either |
| 482 | + * - select the focused date |
| 483 | + * - navigate to focus a new date |
| 484 | + * - emit a md-calendar-close event if in a md-datepicker panel |
| 485 | + * - emit a md-calendar-parent-action |
| 486 | + * - delegate to normal tab order if the TAB key is pressed in standalone mode |
476 | 487 | * @param {KeyboardEvent} event
|
477 | 488 | */
|
478 | 489 | CalendarCtrl.prototype.handleKeyEvent = function(event) {
|
|
481 | 492 | this.$scope.$apply(function() {
|
482 | 493 | // Capture escape and emit back up so that a wrapping component
|
483 | 494 | // (such as a date-picker) can decide to close.
|
484 |
| - if (event.which === self.keyCode.ESCAPE || event.which === self.keyCode.TAB) { |
| 495 | + if (event.which === self.keyCode.ESCAPE || |
| 496 | + (event.which === self.keyCode.TAB && !self.standaloneMode)) { |
485 | 497 | self.$scope.$emit('md-calendar-close');
|
486 | 498 |
|
487 | 499 | if (event.which === self.keyCode.TAB) {
|
488 | 500 | event.preventDefault();
|
489 | 501 | }
|
490 | 502 |
|
| 503 | + return; |
| 504 | + } else if (event.which === self.keyCode.TAB && self.standaloneMode) { |
| 505 | + // delegate to the normal tab order if the TAB key is pressed in standalone mode |
491 | 506 | return;
|
492 | 507 | }
|
493 | 508 |
|
|
0 commit comments