Fix that navbar forgets active state after refresh (#4831)

This commit is contained in:
Sukhwinder Dhillon 2022-06-29 14:58:02 +02:00 committed by GitHub
parent 8e64c0b239
commit 3482ef9e65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 9 deletions

View File

@ -31,8 +31,6 @@ class ConfigMenu extends BaseHtmlElement
protected $selected; protected $selected;
protected $cogItemActive = false;
protected $state; protected $state;
public function __construct() public function __construct()
@ -143,10 +141,6 @@ class ConfigMenu extends BaseHtmlElement
), ),
$this->createLevel2Menu() $this->createLevel2Menu()
]); ]);
if ($this->cogItemActive) {
$cogMenuItem->addAttributes([ 'class' => 'active' ]);
}
} }
protected function assembleLevel2Nav(BaseHtmlElement $level2Nav) protected function assembleLevel2Nav(BaseHtmlElement $level2Nav)
@ -275,7 +269,6 @@ class ConfigMenu extends BaseHtmlElement
if ($this->isSelectedItem($item)) { if ($this->isSelectedItem($item)) {
$li->addAttributes(['class' => 'selected']); $li->addAttributes(['class' => 'selected']);
$this->cogItemActive = true;
} }
return $li; return $li;

View File

@ -222,13 +222,15 @@
Navigation.prototype.setActiveAndSelected = function ($el) { Navigation.prototype.setActiveAndSelected = function ($el) {
if ($el.length > 1) { if ($el.length > 1) {
$el.each(el => { $el.each((key, el) => {
if (! this.active) { if (! this.active) {
this.setActiveAndSelected($(el)); this.setActiveAndSelected($(el));
} }
}); });
} else if ($el.length) { } else if ($el.length) {
if ($el[0].offsetWidth || $el[0].offsetHeight || $el.closest('.config-menu').length) { let parent = $el[0].closest('.nav-level-1 > .nav-item, .config-menu');
if ($el[0].offsetHeight || $el[0].offsetWidth || parent.offsetHeight || parent.offsetWidth) {
// It's either a visible menu item or a config menu item // It's either a visible menu item or a config menu item
this.setActive($el); this.setActive($el);
this.setSelected($el); this.setSelected($el);