Skip to content

Commit c6b8d3b

Browse files
Portugal, Marcelomportuga
Portugal, Marcelo
authored andcommitted
fix(ui-grid-header-cell): Improved styles with grid menu.
Fixed some of the more blatant issues of overlap between the grid menu and the last visible column, although some issues remain with the timing of the digest cycle. Also, updated the grid menu styles a bit based on some CSS suggestions. fix #4337, fix #5051, fix #5557
1 parent 5157ce6 commit c6b8d3b

File tree

7 files changed

+66
-26
lines changed

7 files changed

+66
-26
lines changed

src/js/core/directives/ui-grid-header-cell.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,10 @@
246246
contents.addClass(classAdded);
247247

248248
$scope.$applyAsync(function() {
249-
var rightMostContainer = $scope.grid.renderContainers['right'] ? $scope.grid.renderContainers['right'] : $scope.grid.renderContainers['body'];
250-
$scope.isLastCol = ( $scope.col === rightMostContainer.visibleColumnCache[ rightMostContainer.visibleColumnCache.length - 1 ] );
249+
var rightMostContainer = $scope.grid.renderContainers['right'] && $scope.grid.renderContainers['right'].visibleColumnCache.length ?
250+
$scope.grid.renderContainers['right'] : $scope.grid.renderContainers['body'];
251+
$scope.isLastCol = uiGridCtrl.grid.options && uiGridCtrl.grid.options.enableGridMenu &&
252+
$scope.col === rightMostContainer.visibleColumnCache[ rightMostContainer.visibleColumnCache.length - 1 ];
251253
});
252254

253255
// Figure out whether this column is sortable or not
@@ -371,7 +373,7 @@
371373
event.preventDefault();
372374
$scope.toggleMenu(event);
373375
}
374-
};
376+
};
375377

376378
$scope.toggleMenu = function(event) {
377379

src/less/footer.less

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
}
7272

7373
input[type="text"].ui-grid-filter-input {
74-
padding: 0;
74+
padding: 0 18px 0 0;
7575
margin: 0;
7676
border: 0;
7777
width: 100%;
@@ -82,4 +82,4 @@ input[type="text"].ui-grid-filter-input {
8282
&:hover {
8383
border: @gridBorderWidth solid @borderColor;
8484
}
85-
}
85+
}

src/less/header.less

+19-3
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,24 @@
104104
}
105105
}
106106

107-
.ui-grid-column-menu-button-last-col {
108-
margin-right: 25px;
107+
.ui-grid-header-cell-last-col {
108+
.ui-grid-cell-contents,
109+
.ui-grid-filter-container,
110+
.ui-grid-column-menu-button,
111+
& + .ui-grid-column-resizer.right {
112+
margin-right: 13px;
113+
}
114+
}
115+
116+
.ui-grid-render-container-right {
117+
.ui-grid-header-cell-last-col {
118+
.ui-grid-cell-contents,
119+
.ui-grid-filter-container,
120+
.ui-grid-column-menu-button,
121+
& + .ui-grid-column-resizer.right {
122+
margin-right: 28px;
123+
}
124+
}
109125
}
110126

111127
.ui-grid-column-menu {
@@ -195,7 +211,7 @@
195211
}
196212

197213
input[type="text"].ui-grid-filter-input {
198-
padding: 0;
214+
padding: 0 18px 0 0;
199215
margin: 0;
200216
border: 0;
201217
width: 100%;

src/less/menu.less

+18-10
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,49 @@
44
right: 0;
55
top: 0;
66
background: @headerBackgroundColor;
7-
border: @gridBorderWidth solid @borderColor;
7+
border: 0;
8+
border-left: @gridBorderWidth solid @borderColor;
9+
border-bottom: @gridBorderWidth solid @borderColor;
810
cursor: pointer;
9-
height: 31px;
11+
height: 32px;
1012
font-weight: normal;
1113
}
1214

1315
.ui-grid-menu-button .ui-grid-icon-container {
14-
margin-top: 3px;
16+
margin-top: 5px;
17+
margin-left: 2px;
1518
}
1619

1720
.ui-grid-menu-button .ui-grid-menu {
1821
right: 0;
1922
.ui-grid-menu-mid {
2023
overflow: scroll;
21-
border: @gridBorderWidth solid @borderColor;
2224
}
2325
}
2426

2527
.ui-grid-menu {
28+
max-width: 320px;
2629
z-index: 2; // So it shows up over grid canvas
2730
position: absolute;
2831
padding: 0 10px 20px 10px;
2932
cursor: pointer;
3033
box-sizing: border-box;
3134
}
3235

36+
.ui-grid-menu-item {
37+
width: 100%;
38+
overflow: hidden;
39+
text-overflow: ellipsis;
40+
white-space: nowrap;
41+
}
42+
3343
.ui-grid-menu .ui-grid-menu-inner {
34-
background: @headerBackgroundColor;
44+
background: @menuBackgroundColor;
3545
border: @gridBorderWidth solid @borderColor;
3646
position: relative;
3747
white-space: nowrap;
3848

3949
.rounded(@gridBorderRadius);
40-
.box-shadow(e("0 10px 20px rgba(0, 0, 0, 0.2), inset 0 12px 12px -14px rgba(0, 0, 0, 0.2)"));
4150
}
4251

4352
.ui-grid-menu .ui-grid-menu-inner ul {
@@ -48,6 +57,7 @@
4857
li {
4958
padding: 0px;
5059
button {
60+
color: @menuTextColor;
5161
min-width: 100%;
5262
padding: 8px;
5363
text-align: left;
@@ -57,12 +67,10 @@
5767
// Show a shadow when hovering over a menu item
5868
&:hover,
5969
&:focus {
60-
// background-color: negation(@headerBackgroundColor, #fff);
61-
.inner-shadow(@vertical: 0, @blur: 14px, @alpha: 0.2);
70+
background-color: @menuHoverColor;
6271
}
6372
&.ui-grid-menu-item-active {
64-
.inner-shadow(@vertical: 0, @blur: 14px, @alpha: 0.2);
65-
background-color: @selectedColor;
73+
background-color: @menuSelectedColor;
6674
}
6775
}
6876
}

src/less/variables.less

+11-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
@gridBorderWidth: 1px;
1212
@gridBorderRadius: 0px;
1313
@borderColor: #d4d4d4;
14-
14+
@focusColor: #b3c4c7;
15+
@activeColor: darken(@focusColor, 8%);
1516

1617
/**
1718
* @section Header styles
@@ -32,7 +33,13 @@
3233
@rowColorEven: #f3f3f3;
3334
@rowColorOdd: #fdfdfd;
3435

35-
// TODO: colors for buttons
36+
/**
37+
* @section Grid Menu colors
38+
*/
39+
@menuBackgroundColor: #fff;
40+
@menuHoverColor: @focusColor;
41+
@menuSelectedColor: @activeColor;
42+
@menuTextColor: #000;
3643

3744
/**
3845
* @section Sort arrow colors
@@ -42,18 +49,17 @@
4249
@sortArrowBorderColor: #777777;
4350

4451

45-
// TODO: color for menu background
4652
@rowHeaderCell: #F0F0EE;
4753
@rowSelected: #C9DDE1;
4854
@rowSavingForeground: #848484;
4955
@rowErrorForeground: #FF0000;
5056
@rowDirtyForeground: #610B38;
5157

5258
// TODO: color for cell selections
53-
@focusedCell: #b3c4c7;
59+
@focusedCell: @focusColor;
5460

5561
// Color to use for enabled or selected settings/items/cells, etc. Should probably override the one above
56-
@selectedColor: #cecece;
62+
@selectedColor: @activeColor;
5763

5864
/**
5965
* @section Scrollbar styles

src/templates/ui-grid/uiGridHeaderCell.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div
22
role="columnheader"
3-
ng-class="{ 'sortable': sortable }"
3+
ng-class="{ 'sortable': sortable, 'ui-grid-header-cell-last-col': isLastCol }"
44
ui-grid-one-bind-aria-labelledby-grid="col.uid + '-header-text ' + col.uid + '-sortdir-text'"
55
aria-sort="{{col.sort.direction == asc ? 'ascending' : ( col.sort.direction == desc ? 'descending' : (!col.sort.direction ? 'none' : 'other'))}}">
66
<div
@@ -41,7 +41,6 @@
4141
ng-if="grid.options.enableColumnMenus && !col.isRowHeader && col.colDef.enableColumnMenu !== false"
4242
ng-click="toggleMenu($event)"
4343
ng-keydown="headerCellArrowKeyDown($event)"
44-
ng-class="{'ui-grid-column-menu-button-last-col': isLastCol}"
4544
ui-grid-one-bind-aria-label="i18n.headerCell.aria.columnMenuButtonLabel"
4645
aria-haspopup="true">
4746
<i

test/unit/core/directives/ui-grid-header-cell.spec.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('uiGridHeaderCell', function() {
6868
$compile(grid)($scope);
6969
$document[0].body.appendChild(grid[0]);
7070

71-
$scope.$digest();
71+
$scope.$apply();
7272
};
7373

7474
recompile();
@@ -193,6 +193,15 @@ describe('uiGridHeaderCell', function() {
193193
}));
194194
});
195195

196+
describe('isLastCol', function() {
197+
it('should not add a last col class to the last column when the grid menu is disabled', function() {
198+
expect($(grid).find('.ui-grid-header-cell:nth(2) .sortable').hasClass('ui-grid-header-cell-last-col')).toBe(false);
199+
});
200+
it('should not add a last col class to a column that is not the last column', function() {
201+
expect($(grid).find('.ui-grid-header-cell:nth(1) .sortable').hasClass('ui-grid-header-cell-last-col')).toBe(false);
202+
});
203+
});
204+
196205
describe('externalScope', function() {
197206
it('should be present', function() {
198207
var header = $(grid).find('.ui-grid-header-cell:nth(0)');

0 commit comments

Comments
 (0)