From 3085417c36bd5324e8075c66b82b610fd3155743 Mon Sep 17 00:00:00 2001 From: Martijn Welker Date: Mon, 10 Dec 2018 10:39:04 +0100 Subject: [PATCH] fix(uiGridColumMenu): Check for menu item visibility before trying to focus the first visible menu item --- src/js/core/directives/ui-grid-column-menu.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/js/core/directives/ui-grid-column-menu.js b/src/js/core/directives/ui-grid-column-menu.js index ac927bb8a5..ffc1a2164e 100644 --- a/src/js/core/directives/ui-grid-column-menu.js +++ b/src/js/core/directives/ui-grid-column-menu.js @@ -397,8 +397,15 @@ function ($timeout, gridUtil, uiGridConstants, uiGridColumnMenuService, $documen $timeout(function() { uiGridColumnMenuService.repositionMenu( $scope, $scope.col, $scope.colElementPosition, $elm, $scope.colElement ); + var hasVisibleMenuItems = $scope.menuItems.some(function (menuItem) { + return menuItem.shown(); + }); + // automatically set the focus to the first button element in the now open menu. - gridUtil.focus.bySelector($document, '.ui-grid-menu-items .ui-grid-menu-item:not(.ng-hide)', true); + if (hasVisibleMenuItems) { + gridUtil.focus.bySelector($document, '.ui-grid-menu-items .ui-grid-menu-item:not(.ng-hide)', true); + } + delete $scope.colElementPosition; delete $scope.columnElement; addKeydownHandlersToMenu();