|
766 | 766 | };
|
767 | 767 | }]);
|
768 | 768 |
|
769 |
| - module.directive('uiGridViewport', ['$timeout', '$document', 'gridUtil', 'uiGridConstants', 'uiGridCellNavService', 'uiGridCellNavConstants','$log', |
770 |
| - function ($timeout, $document, gridUtil, uiGridConstants, uiGridCellNavService, uiGridCellNavConstants, $log) { |
| 769 | + module.directive('uiGridViewport', ['$timeout', '$document', 'gridUtil', 'uiGridConstants', 'uiGridCellNavService', 'uiGridCellNavConstants','$log','$compile', |
| 770 | + function ($timeout, $document, gridUtil, uiGridConstants, uiGridCellNavService, uiGridCellNavConstants, $log, $compile) { |
| 771 | + var focuser; |
771 | 772 | return {
|
772 | 773 | replace: true,
|
773 | 774 | priority: -99999, //this needs to run very last
|
774 | 775 | require: ['^uiGrid', '^uiGridRenderContainer', '?^uiGridCellnav'],
|
775 | 776 | scope: false,
|
776 | 777 | compile: function () {
|
777 | 778 | return {
|
| 779 | + pre: function ($scope, $elm, $attrs, uiGridCtrl) { |
| 780 | + //add an element with no dimensions that can be used to set focus and capture keystrokes |
| 781 | + focuser = $compile('<div class="ui-grid-focuser" tabindex="-1"></div>')($scope); |
| 782 | + $elm.append(focuser); |
| 783 | + }, |
778 | 784 | post: function ($scope, $elm, $attrs, controllers) {
|
779 | 785 | var uiGridCtrl = controllers[0],
|
780 | 786 | renderContainerCtrl = controllers[1];
|
|
787 | 793 | var grid = uiGridCtrl.grid;
|
788 | 794 |
|
789 | 795 |
|
790 |
| - // Let the render container be focus-able |
791 |
| - $elm.attr("tabindex", -1); |
| 796 | + focuser[0].focus(); |
792 | 797 |
|
793 | 798 | // Bind to keydown events in the render container
|
794 |
| - $elm.on('keydown', function (evt) { |
| 799 | + focuser.on('keydown', function (evt) { |
795 | 800 | evt.uiGridTargetRenderContainerId = containerId;
|
796 | 801 | var rowCol = uiGridCtrl.grid.api.cellNav.getFocusedCell();
|
797 | 802 | var result = uiGridCtrl.cellNav.handleKeyDown(evt);
|
|
839 | 844 | });
|
840 | 845 |
|
841 | 846 | grid.api.cellNav.on.navigate($scope, function () {
|
842 |
| - //focus the viewport because this can sometimes be lost |
843 |
| - $elm[0].focus(); |
| 847 | + //focus again because it can be lost |
| 848 | + focuser[0].focus(); |
844 | 849 | });
|
845 | 850 |
|
846 | 851 | }
|
|
0 commit comments