Skip to content

Commit 156cb26

Browse files
author
Bogdan Plieshka
committed
MAGETWO-35489: Active state is lost for Navigation Menu items in Backend
- Fixed menu events
1 parent afc9c08 commit 156cb26

File tree

4 files changed

+92
-48
lines changed

4 files changed

+92
-48
lines changed

app/code/Magento/Backend/Block/Menu.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ protected function _renderItemCssClass($menuItem, $level)
191191
$output = ($this->_isItemActive(
192192
$menuItem,
193193
$level
194-
) ? '_active' : '') .
194+
) ? '_current _active' : '') .
195195
' ' .
196196
($menuItem->hasChildren() ? 'parent' : '') .
197197
' ' .

app/design/adminhtml/Magento/backend/Magento_Backend/web/css/source/module/_menu.less

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
@menu__background-color: @color-very-dark-grayish-orange;
1717

18-
@menu-logo__margin-bottom: 2.2rem;
19-
@menu-logo__outer-size: @menu-logo__padding-vertical + @menu-logo-img__height + @menu-logo__margin-bottom;
20-
@menu-logo__padding-vertical: 1.2rem;
18+
@menu-logo__padding-bottom: 2.2rem;
19+
@menu-logo__outer-size: @menu-logo__padding-top + @menu-logo-img__height + @menu-logo__padding-bottom;
20+
@menu-logo__padding-top: 1.2rem;
2121
@menu-logo-img__height: 4.1rem;
2222
@menu-logo-img__width: 3.5rem;
2323

@@ -68,12 +68,27 @@
6868
}
6969
.logo {
7070
display: block;
71-
height: @menu-logo-img__height + @menu-logo__padding-vertical * 2;
72-
margin-bottom: @menu-logo__margin-bottom - @menu-logo__padding-vertical;
73-
padding: @menu-logo__padding-vertical 0;
71+
height: @menu-logo-img__height + @menu-logo__padding-top + @menu-logo__padding-bottom;
72+
padding: @menu-logo__padding-top 0 @menu-logo__padding-bottom;
7473
position: relative;
7574
text-align: center;
7675
z-index: @menu__z-index;
76+
&:focus {
77+
background-color: @menu-item__active__background-color;
78+
box-shadow: none;
79+
+ .admin__menu {
80+
.level-0 {
81+
&:first-child {
82+
> a {
83+
background-color: @menu__background-color;
84+
&:after {
85+
display: none;
86+
}
87+
}
88+
}
89+
}
90+
}
91+
}
7792
&:hover {
7893
.logo-img {
7994
-webkit-filter: brightness(1.1);
@@ -133,7 +148,6 @@
133148
}
134149
// Hover & active state for menu level 0 item
135150
&._active,
136-
&._hover,
137151
&:hover {
138152
> a {
139153
background-color: @menu-item__active__background-color;
@@ -185,19 +199,13 @@
185199
transition: all .5s ease;
186200
visibility: hidden;
187201
z-index: @submenu__z-index;
188-
&._show {
202+
}
203+
&._show {
204+
> .submenu {
189205
left: 100%;
190206
visibility: visible;
191207
}
192208
}
193-
&._recent {
194-
&._hover {
195-
.submenu {
196-
left: 100%;
197-
visibility: visible;
198-
}
199-
}
200-
}
201209
}
202210

203211
.level-1 {

app/design/adminhtml/Magento/backend/web/css/override.less

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3119,13 +3119,22 @@ fieldset[disabled] .admin__control-text + .ui-datepicker-trigger {
31193119
}
31203120
.menu-wrapper .logo {
31213121
display: block;
3122-
height: 6.5rem;
3123-
margin-bottom: 1rem;
3124-
padding: 1.2rem 0;
3122+
height: 7.5rem;
3123+
padding: 1.2rem 0 2.2rem;
31253124
position: relative;
31263125
text-align: center;
31273126
z-index: 700;
31283127
}
3128+
.menu-wrapper .logo:focus {
3129+
background-color: #524d49;
3130+
box-shadow: none;
3131+
}
3132+
.menu-wrapper .logo:focus + .admin__menu .level-0:first-child > a {
3133+
background-color: #373330;
3134+
}
3135+
.menu-wrapper .logo:focus + .admin__menu .level-0:first-child > a:after {
3136+
display: none;
3137+
}
31293138
.menu-wrapper .logo:hover .logo-img {
31303139
-webkit-filter: brightness(1.1);
31313140
filter: brightness(1.1);
@@ -3162,7 +3171,6 @@ fieldset[disabled] .admin__control-text + .ui-datepicker-trigger {
31623171
display: none;
31633172
}
31643173
.admin__menu .level-0._active > a,
3165-
.admin__menu .level-0._hover > a,
31663174
.admin__menu .level-0:hover > a {
31673175
background-color: #524d49;
31683176
color: #f7f3eb;
@@ -3205,11 +3213,7 @@ fieldset[disabled] .admin__control-text + .ui-datepicker-trigger {
32053213
visibility: hidden;
32063214
z-index: 698;
32073215
}
3208-
.admin__menu .level-0 > .submenu._show {
3209-
left: 100%;
3210-
visibility: visible;
3211-
}
3212-
.admin__menu .level-0._recent._hover .submenu {
3216+
.admin__menu .level-0._show > .submenu {
32133217
left: 100%;
32143218
visibility: visible;
32153219
}

app/design/adminhtml/Magento/backend/web/js/theme.js

Lines changed: 54 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ define('globalNavigation', [
1212
$.widget('mage.globalNavigation', {
1313
options: {
1414
selectors: {
15+
menu: '#nav',
16+
currentItem: '._current',
1517
topLevelItem: '.level-0',
1618
topLevelHref: '> a',
1719
subMenu: '> .submenu',
@@ -25,6 +27,7 @@ define('globalNavigation', [
2527

2628
this.menu = this.element;
2729
this.menuLinks = $(selectors.topLevelHref, selectors.topLevelItem);
30+
this.closeActions = $(selectors.closeSubmenuBtn);
2831

2932
this._initOverlay()
3033
._bind();
@@ -44,40 +47,66 @@ define('globalNavigation', [
4447
},
4548

4649
_bind: function () {
47-
var lighten = this._lighten.bind(this),
48-
open = this._open.bind(this),
49-
darken = this._darken.bind(this);
50+
var focus = this._focus.bind(this),
51+
open = this._open.bind(this),
52+
blur = this._blur.bind(this),
53+
keyboard = this._keyboard.bind(this);
5054

5155
this.menuLinks
52-
.on('focus', lighten)
53-
.on('click', open)
54-
.on('blur', darken);
56+
.on('focus', focus)
57+
.on('click', open);
58+
59+
this.menuLinks.last().on('blur', blur);
60+
61+
this.closeActions.on('keydown', keyboard);
62+
},
63+
64+
65+
/**
66+
* Remove active class from current menu item
67+
* Turn back active class to current page menu item
68+
*/
69+
_blur: function(e){
70+
var selectors = this.options.selectors,
71+
menuItem = $(e.target).closest(selectors.topLevelItem),
72+
currentItem = $(selectors.menu).find(selectors.currentItem);
73+
74+
menuItem.removeClass('_active');
75+
currentItem.addClass('_active');
5576
},
5677

57-
_lighten: function (e) {
78+
/**
79+
* Add focus to active menu item
80+
*/
81+
_keyboard: function(e) {
5882
var selectors = this.options.selectors,
5983
menuItem = $(e.target).closest(selectors.topLevelItem);
6084

61-
menuItem
62-
.addClass('_active')
63-
.siblings(selectors.topLevelItem)
64-
.removeClass('_active');
85+
if(e.which === 13) {
86+
this._close(e);
87+
$(selectors.topLevelHref, menuItem).focus();
88+
}
6589
},
6690

67-
_darken: function (e) {
91+
/**
92+
* Toggle active state on focus
93+
*/
94+
_focus: function (e) {
6895
var selectors = this.options.selectors,
6996
menuItem = $(e.target).closest(selectors.topLevelItem);
7097

71-
menuItem.removeClass('_active');
98+
menuItem.addClass('_active')
99+
.siblings(selectors.topLevelItem)
100+
.removeClass('_active');
72101
},
73102

74103
_closeSubmenu: function (e) {
75104
var selectors = this.options.selectors,
76-
menuItem = $(e.target).closest(selectors.topLevelItem);
105+
currentItem = $(selectors.menu).find(selectors.currentItem);
77106

78107
this._close(e);
79108

80-
$(selectors.topLevelHref, menuItem).focus();
109+
currentItem.addClass('_active');
81110
},
82111

83112
_open: function (e) {
@@ -92,33 +121,36 @@ define('globalNavigation', [
92121
e.preventDefault();
93122
}
94123

95-
menuItem
96-
.addClass('_hover _recent')
97-
.siblings(menuItemSelector)
98-
.removeClass('_hover _recent');
124+
menuItem.addClass('_show')
125+
.siblings(menuItemSelector)
126+
.removeClass('_show');
99127

100128
subMenu.attr('aria-expanded', 'true');
101129

102130
closeBtn.on('click', close);
103131

104132
this.overlay.show(0).on('click', close);
133+
this.menuLinks.last().off('blur');
105134
},
106135

107136
_close: function (e) {
108137
var selectors = this.options.selectors,
109-
menuItem = this.menu.find(selectors.topLevelItem + '._hover._recent'),
138+
menuItem = this.menu.find(selectors.topLevelItem + '._show'),
110139
subMenu = $(selectors.subMenu, menuItem),
111-
closeBtn = subMenu.find(selectors.closeSubmenuBtn);
140+
closeBtn = subMenu.find(selectors.closeSubmenuBtn),
141+
blur = this._blur.bind(this);
112142

113143
e.preventDefault();
114144

115145
this.overlay.hide(0).off('click');
116146

147+
this.menuLinks.last().on('blur', blur);
148+
117149
closeBtn.off('click');
118150

119151
subMenu.attr('aria-expanded', 'false');
120152

121-
menuItem.removeClass('_hover _recent');
153+
menuItem.removeClass('_show _active');
122154
}
123155
});
124156

0 commit comments

Comments
 (0)