|
638 | 638 | // gridUtil.logDebug('uiGridEdit preLink');
|
639 | 639 | uiGridCtrl.cellNav.broadcastCellNav = function (newRowCol) {
|
640 | 640 | $scope.$broadcast(uiGridCellNavConstants.CELL_NAV_EVENT, newRowCol);
|
641 |
| - uiGridCtrl.cellNav.broadcastFocus(newRowCol.row, newRowCol.col); |
| 641 | + uiGridCtrl.cellNav.broadcastFocus(newRowCol); |
642 | 642 | };
|
643 | 643 |
|
644 |
| - uiGridCtrl.cellNav.broadcastFocus = function (row, col) { |
| 644 | + uiGridCtrl.cellNav.broadcastFocus = function (rowCol) { |
| 645 | + var row = rowCol.row, |
| 646 | + col = rowCol.col; |
| 647 | + |
645 | 648 | if (grid.cellNav.lastRowCol === null || (grid.cellNav.lastRowCol.row !== row || grid.cellNav.lastRowCol.col !== col)) {
|
646 | 649 | var newRowCol = new RowCol(row, col);
|
647 | 650 | grid.api.cellNav.raise.navigate(newRowCol, grid.cellNav.lastRowCol);
|
|
688 | 691 | };
|
689 | 692 | }]);
|
690 | 693 |
|
691 |
| - module.directive('uiGridRenderContainer', ['$timeout', 'gridUtil', 'uiGridConstants', 'uiGridCellNavService', 'uiGridCellNavConstants', |
692 |
| - function ($timeout, gridUtil, uiGridConstants, uiGridCellNavService, uiGridCellNavConstants) { |
| 694 | + module.directive('uiGridRenderContainer', ['$timeout', '$document', 'gridUtil', 'uiGridConstants', 'uiGridCellNavService', 'uiGridCellNavConstants', |
| 695 | + function ($timeout, $document, gridUtil, uiGridConstants, uiGridCellNavService, uiGridCellNavConstants) { |
693 | 696 | return {
|
694 | 697 | replace: true,
|
695 | 698 | priority: -99999, //this needs to run very last
|
|
706 | 709 | var containerId = renderContainerCtrl.containerId;
|
707 | 710 |
|
708 | 711 | var grid = uiGridCtrl.grid;
|
709 |
| - //needs to run last after all renderContainers are built |
| 712 | + |
| 713 | + // Needs to run last after all renderContainers are built |
710 | 714 | uiGridCellNavService.decorateRenderContainers(grid);
|
711 | 715 |
|
| 716 | + // Let the render container be focus-able |
| 717 | + $elm.attr("tabindex", -1); |
| 718 | + |
712 | 719 | // Bind to keydown events in the render container
|
713 | 720 | $elm.on('keydown', function (evt) {
|
714 | 721 | evt.uiGridTargetRenderContainerId = containerId;
|
|
717 | 724 |
|
718 | 725 | // When there's a scroll event we need to make sure to re-focus the right row, because the cell contents may have changed
|
719 | 726 | $scope.$on(uiGridConstants.events.GRID_SCROLL, function (evt, args) {
|
| 727 | + // Skip if there's no currently-focused cell |
720 | 728 | if (uiGridCtrl.grid.api.cellNav.getFocusedCell() == null) {
|
721 | 729 | return;
|
722 | 730 | }
|
|
727 | 735 | // Get the last row+col combo
|
728 | 736 | var lastRowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell();
|
729 | 737 |
|
| 738 | + // If the body element becomes active, re-focus on the render container so we can capture cellNav events again. |
| 739 | + // NOTE: this happens when we navigate LET from the left-most cell (RIGHT from the right-most) and have to re-render a new |
| 740 | + // set of cells. The cell element we are navigating to doesn't exist and focus gets lost. This will re-capture it, imperfectly... |
| 741 | + if ($document.activeElement === $document.body) { |
| 742 | + $elm[0].focus(); |
| 743 | + } |
| 744 | + |
730 | 745 | // Re-broadcast a cellNav event so we re-focus the right cell
|
731 | 746 | uiGridCtrl.cellNav.broadcastCellNav(lastRowCol);
|
732 | 747 | });
|
|
772 | 787 | rowCol.col === $scope.col) {
|
773 | 788 | setFocused();
|
774 | 789 |
|
775 |
| - if ( |
776 |
| - // This cellNav event came from a keydown event so we can safely refocus |
777 |
| - (rowCol.hasOwnProperty('eventType') && rowCol.eventType === uiGridCellNavConstants.EVENT_TYPE.KEYDOWN) |
778 |
| - // The focus has gone to the body element, because we've probably wrapped around |
779 |
| - // ($document.activeElement === $document.body) |
780 |
| - ) { |
| 790 | + // This cellNav event came from a keydown event so we can safely refocus |
| 791 | + if (rowCol.hasOwnProperty('eventType') && rowCol.eventType === uiGridCellNavConstants.EVENT_TYPE.KEYDOWN) { |
781 | 792 | $elm.find('div')[0].focus();
|
782 | 793 | }
|
783 | 794 | }
|
|
0 commit comments