client/menus: avoid unnecessary menu item no-column-break grouping

This commit is contained in:
Adorian Doran 2025-09-20 03:09:56 +03:00
parent 9a9edf16c4
commit a92604e92f

View File

@ -155,7 +155,7 @@ class ContextMenu {
.addClass("show"); .addClass("show");
} }
addItems($parent: JQuery<HTMLElement>, items: MenuItem<any>[]) { addItems($parent: JQuery<HTMLElement>, items: MenuItem<any>[], multicolumn = false) {
let $group = $parent; let $group = $parent;
let shouldResetGroup = false; // If true, the next item will be the last one from the group let shouldResetGroup = false; // If true, the next item will be the last one from the group
@ -169,8 +169,8 @@ class ContextMenu {
// before and after the seaparator/header. // before and after the seaparator/header.
// This is a workaround for Firefox not supporting break-after: avoid on columns. // This is a workaround for Firefox not supporting break-after: avoid on columns.
const nextItem = (index < items.length - 1) ? items[index + 1] : null; const nextItem = (index < items.length - 1) ? items[index + 1] : null;
if (!shouldResetGroup && nextItem && "kind" in nextItem) { if (multicolumn && nextItem && "kind" in nextItem) {
if (nextItem.kind === "separator" || nextItem.kind === "header") { if (!shouldResetGroup && (nextItem.kind === "separator" || nextItem.kind === "header")) {
$group = $("<div class='dropdown-no-break'>"); $group = $("<div class='dropdown-no-break'>");
$parent.append($group); $parent.append($group);
} }
@ -283,11 +283,12 @@ class ContextMenu {
$link.addClass("dropdown-toggle"); $link.addClass("dropdown-toggle");
const $subMenu = $("<ul>").addClass("dropdown-menu"); const $subMenu = $("<ul>").addClass("dropdown-menu");
if (!this.isMobile && item.columns) { const hasColumns = !!item.columns && item.columns > 1;
$subMenu.css("column-count", item.columns); if (!this.isMobile && hasColumns) {
$subMenu.css("column-count", item.columns!);
} }
this.addItems($subMenu, item.items); this.addItems($subMenu, item.items, hasColumns);
$item.append($subMenu); $item.append($subMenu);
} }