Skip to content

Commit 0264b11

Browse files
committed
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 angular-ui#3436, angular-ui#3921, angular-ui#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 angular-ui#6587.
1 parent bf0267c commit 0264b11

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
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">

0 commit comments

Comments
 (0)