Skip to content

Commit 25dbd2e

Browse files
caseyjholmportuga
authored andcommitted
fix(menus): Fix menu positioning/animation
Since v3.0.0-rc.21, the column/grid menu animation slides down from above the grid, but it is visible the entire time. This causes the animation to appear clunky. This has been resolved by setting `overflow: hidden` on the menu. Fixes #3436, #3921, #3978. Showing/hiding the menu can seem slow. The menu animation has been sped up as well, and when it is hidden, the animation is now twice as fast. Previously, to calculate the menu position, the width of the menu needed to be calculated, which meant calling `repositionMenu` twice - once when first opening the menu, and again after the menu is visible to allow the width of the menu to be determined. This also meant there was always a "shift" when the menu was first opened (as a default width of 170px was used until the actual width of the menu could be determined. This implements the CSS trick `right: 100%` so the width is not needed when determining the menu's position, meaning the menu can be opened much more smoothly and without needing to call `repositionMenu` twice. Fixes #6587. remove lastMenuWidth from tests no message
1 parent 0e83225 commit 25dbd2e

File tree

6 files changed

+30
-30
lines changed

6 files changed

+30
-30
lines changed

src/js/core/directives/ui-grid-column-menu.js

+4-11
Original file line numberDiff line numberDiff line change
@@ -274,17 +274,11 @@ function ( i18nService, uiGridConstants, gridUtil ) {
274274

275275
var containerScrollLeft = renderContainerElm.querySelectorAll('.ui-grid-viewport')[0].scrollLeft;
276276

277-
// default value the last width for _this_ column, otherwise last width for _any_ column, otherwise default to 170
278-
var myWidth = column.lastMenuWidth ? column.lastMenuWidth : ( $scope.lastMenuWidth ? $scope.lastMenuWidth : 170);
279277
var paddingRight = column.lastMenuPaddingRight ? column.lastMenuPaddingRight : ( $scope.lastMenuPaddingRight ? $scope.lastMenuPaddingRight : 10);
280278

281279
if ( menu.length !== 0 ){
282280
var mid = menu[0].querySelectorAll('.ui-grid-menu-mid');
283-
if ( mid.length !== 0 && !angular.element(mid).hasClass('ng-hide') ) {
284-
myWidth = gridUtil.elementWidth(menu, true);
285-
$scope.lastMenuWidth = myWidth;
286-
column.lastMenuWidth = myWidth;
287-
281+
if ( mid.length !== 0 ) {
288282
// TODO(c0bra): use padding-left/padding-right based on document direction (ltr/rtl), place menu on proper side
289283
// Get the column menu right padding
290284
paddingRight = parseInt(gridUtil.getStyles(angular.element(menu)[0])['paddingRight'], 10);
@@ -293,7 +287,7 @@ function ( i18nService, uiGridConstants, gridUtil ) {
293287
}
294288
}
295289

296-
var left = positionData.left + renderContainerOffset - containerScrollLeft + positionData.parentLeft + positionData.width - myWidth + paddingRight;
290+
var left = positionData.left + renderContainerOffset - containerScrollLeft + positionData.parentLeft + positionData.width + paddingRight;
297291
if (left < positionData.offset){
298292
left = positionData.offset;
299293
}
@@ -409,12 +403,11 @@ function ($timeout, gridUtil, uiGridConstants, uiGridColumnMenuService, $documen
409403

410404
$scope.$on('menu-shown', function() {
411405
$timeout( function() {
412-
uiGridColumnMenuService.repositionMenu( $scope, $scope.col, $scope.colElementPosition, $elm, $scope.colElement );
413-
//Focus on the first item
406+
//automatically set the focus to the first button element in the now open menu.
414407
gridUtil.focus.bySelector($document, '.ui-grid-menu-items .ui-grid-menu-item', true);
415408
delete $scope.colElementPosition;
416409
delete $scope.columnElement;
417-
}, 200);
410+
});
418411
});
419412

420413

src/js/core/directives/ui-grid-menu.js

-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ function ($compile, $timeout, $window, $document, gridUtil, uiGridConstants, i18
120120
$elm.on('keyup', checkKeyUp);
121121
$elm.on('keydown', checkKeyDown);
122122
});
123-
//automatically set the focus to the first button element in the now open menu.
124-
gridUtil.focus.bySelector($elm, 'button[type=button]', true);
125123
};
126124

127125

src/less/header.less

+14-4
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,13 @@
130130

131131
/* Slide up/down animations */
132132
.ui-grid-column-menu .ui-grid-menu .ui-grid-menu-mid {
133-
&.ng-hide-add, &.ng-hide-remove {
134-
.transition(all, 0.05s, linear);
133+
&.ng-hide-add {
134+
.transition(all, 0.04s, linear);
135+
display: block !important;
136+
}
137+
138+
&.ng-hide-remove {
139+
.transition(all, 0.02s, linear);
135140
display: block !important;
136141
}
137142

@@ -148,8 +153,13 @@
148153

149154
/* Slide up/down animations */
150155
.ui-grid-menu-button .ui-grid-menu .ui-grid-menu-mid {
151-
&.ng-hide-add, &.ng-hide-remove {
152-
.transition(all, 0.05s, linear);
156+
&.ng-hide-add {
157+
.transition(all, 0.04s, linear);
158+
display: block !important;
159+
}
160+
161+
&.ng-hide-remove {
162+
.transition(all, 0.02s, linear);
153163
display: block !important;
154164
}
155165

src/less/menu.less

+2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
}
2626

2727
.ui-grid-menu {
28+
overflow: hidden;
2829
max-width: 320px;
2930
z-index: 2; // So it shows up over grid canvas
3031
position: absolute;
32+
right: 100%;
3133
padding: 0 10px 20px 10px;
3234
cursor: pointer;
3335
box-sizing: border-box;

src/templates/ui-grid/uiGridMenu.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<div
22
class="ui-grid-menu"
3-
ng-if="shown">
3+
ng-show="shown">
44
<style ui-grid-style>
55
{{dynamicStyles}}
66
</style>
77
<div
88
class="ui-grid-menu-mid"
99
ng-show="shownMid">
1010
<div
11-
class="ui-grid-menu-inner">
11+
class="ui-grid-menu-inner"
12+
ng-if="shown">
1213
<ul
1314
role="menu"
1415
class="ui-grid-menu-items">

test/unit/core/directives/ui-grid-column-menu.spec.js

+7-11
Original file line numberDiff line numberDiff line change
@@ -461,27 +461,25 @@ describe('ui-grid-column-menu uiGridColumnMenuService', function() {
461461
renderContainerElm.querySelectorAll.calls.reset();
462462
$elm.css.calls.reset();
463463
});
464-
describe('when the current column has a lastMenuWidth and lastMenuPaddingRight defined', function() {
464+
describe('when the current column has a lastMenuPaddingRight defined', function() {
465465
beforeEach(function() {
466466
column = {
467-
lastMenuWidth: 100,
468467
lastMenuPaddingRight: 150
469468
};
470469
left = positionData.left + renderContainerElm.getBoundingClientRect().left - $scope.grid.element[0].getBoundingClientRect().left -
471-
renderContainerElm.querySelectorAll()[0].scrollLeft + positionData.parentLeft + positionData.width - column.lastMenuWidth +
470+
renderContainerElm.querySelectorAll()[0].scrollLeft + positionData.parentLeft + positionData.width +
472471
column.lastMenuPaddingRight;
473472
});
474473
it('should use them to calculate the left position of the element', function() {
475474
uiGridColumnMenuService.repositionMenu($scope, column, positionData, $elm, $columnElement);
476475
expect($elm.css).toHaveBeenCalledWith('left', left + 'px');
477476
});
478477
});
479-
describe('when the current column does not have lastMenuWidth and lastMenuPaddingRight defined, but $scope does', function() {
478+
describe('when the current column does not have lastMenuPaddingRight defined, but $scope does', function() {
480479
beforeEach(function() {
481-
$scope.lastMenuWidth = 100;
482480
$scope.lastMenuPaddingRight = 150;
483481
left = positionData.left + renderContainerElm.getBoundingClientRect().left - $scope.grid.element[0].getBoundingClientRect().left -
484-
renderContainerElm.querySelectorAll()[0].scrollLeft + positionData.parentLeft + positionData.width - $scope.lastMenuWidth +
482+
renderContainerElm.querySelectorAll()[0].scrollLeft + positionData.parentLeft + positionData.width +
485483
$scope.lastMenuPaddingRight;
486484
});
487485
it('should use them to calculate the left position of the element', function() {
@@ -491,10 +489,9 @@ describe('ui-grid-column-menu uiGridColumnMenuService', function() {
491489
});
492490
describe('when the left position is less the postion data offset', function() {
493491
beforeEach(function() {
494-
$scope.lastMenuWidth = 100;
495492
$scope.lastMenuPaddingRight = 150;
496493
left = positionData.left + renderContainerElm.getBoundingClientRect().left - $scope.grid.element[0].getBoundingClientRect().left -
497-
renderContainerElm.querySelectorAll()[0].scrollLeft + positionData.parentLeft + positionData.width - $scope.lastMenuWidth +
494+
renderContainerElm.querySelectorAll()[0].scrollLeft + positionData.parentLeft + positionData.width +
498495
$scope.lastMenuPaddingRight;
499496
positionData.offset = left + 10;
500497
});
@@ -508,13 +505,12 @@ describe('ui-grid-column-menu uiGridColumnMenuService', function() {
508505
$elm[0].querySelectorAll.and.returnValue([{
509506
querySelectorAll: jasmine.createSpy('querySelectorAll').and.returnValue('<div></div>')
510507
}]);
511-
$scope.lastMenuWidth = 100;
512508
$scope.lastMenuPaddingRight = 150;
513509
left = positionData.left + renderContainerElm.getBoundingClientRect().left - $scope.grid.element[0].getBoundingClientRect().left -
514-
renderContainerElm.querySelectorAll()[0].scrollLeft + positionData.parentLeft + positionData.width - gridUtil.elementWidth() +
510+
renderContainerElm.querySelectorAll()[0].scrollLeft + positionData.parentLeft + positionData.width +
515511
gridUtil.getStyles().paddingRight;
516512
});
517-
it('should use the position menu width and right padding to calculate the left position of the element', function() {
513+
it('should use the position and right padding to calculate the left position of the element', function() {
518514
uiGridColumnMenuService.repositionMenu($scope, column, positionData, $elm, $columnElement);
519515
expect($elm.css).toHaveBeenCalledWith('left', left + 'px');
520516
});

0 commit comments

Comments
 (0)