Skip to content

Commit

Permalink
Merge pull request #1 from krassowski/collapse-menu-review
Browse files Browse the repository at this point in the history
Collapse logic to reduce code complexity
  • Loading branch information
steff456 authored Jan 31, 2023
2 parents c14d733 + fcc357b commit 8cca0f6
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions packages/widgets/src/menubar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,9 @@ export class MenuBar extends Widget {

// Render visible menus
for (let i = 0; i < length; ++i) {
let title = menus[i].title;
let active = i === activeIndex;
if (active && menus[i].items.length == 0) {
active = false;
}
content[i] = renderer.renderItem({
title,
active,
title: menus[i].title,
active: i === activeIndex && menus[i].items.length !== 0,
onfocus: () => {
this.activeIndex = i;
}
Expand All @@ -447,14 +442,9 @@ export class MenuBar extends Widget {
});
this.removeMenu(submenu, false);
}
let title = this._overflowMenu.title;
let active = length === activeIndex;
if (active && menus[length].items.length == 0) {
active = false;
}
content[length] = renderer.renderOverflowItem({
title,
active,
title: this._overflowMenu.title,
active: length === activeIndex && menus[length].items.length !== 0,
onfocus: () => {
this.activeIndex = length;
}
Expand All @@ -470,11 +460,9 @@ export class MenuBar extends Widget {
let menu = overflowMenuItems[0].submenu as Menu;
this._overflowMenu.removeItemAt(0);
this.insertMenu(length, menu, false);
let title = menu.title;
let active = false;
content[length] = renderer.renderItem({
title,
active,
title: menu.title,
active: false,
onfocus: () => {
this.activeIndex = length;
}
Expand Down

0 comments on commit 8cca0f6

Please sign in to comment.