Skip to content

A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.

fix: unify collapsible container headers and spacing (#7153)

Thomas5a3091547c3c
diff --git a/apps/nextjs/src/components/board/layout/constants.ts b/apps/nextjs/src/components/board/layout/constants.ts
index e4f309700..5ad82d55e 100644
--- a/apps/nextjs/src/components/board/layout/constants.ts
+++ b/apps/nextjs/src/components/board/layout/constants.ts
@@ -7,3 +7,4 @@ export const LOGICAL_GRID_GAP = 12;
export const LOGICAL_GRID_PITCH = LOGICAL_GRID_CELL_SIZE + LOGICAL_GRID_GAP;
export const COLLAPSED_SECTION_ROW_COUNT = 0.5;
+export const CONTAINER_HEADER_HEIGHT = 48;
diff --git a/apps/nextjs/src/components/board/layout/reflow.ts b/apps/nextjs/src/components/board/layout/reflow.ts
index 4aafd7611..1017d37a9 100644
--- a/apps/nextjs/src/components/board/layout/reflow.ts
+++ b/apps/nextjs/src/components/board/layout/reflow.ts
@@ -15,6 +15,7 @@ interface CollapsedLayoutOptions {
columnCount: number;
collapsedItemIds: ReadonlySet<string>;
collapsedRowCount?: number;
+ collapsedRowCountById?: ReadonlyMap<string, number>;
}
export const doGridPlacementsOverlap = (first: GridPlacement, second: GridPlacement) =>
@@ -61,23 +62,28 @@ export const reflowVerticalLayout = <TPlacement extends GridPlacement>(
*/
export const getCollapsedDisplayLayout = <TPlacement extends GridPlacement>(
placements: readonly TPlacement[],
- { columnCount, collapsedItemIds, collapsedRowCount = COLLAPSED_SECTION_ROW_COUNT }: CollapsedLayoutOptions,
+ {
+ columnCount,
+ collapsedItemIds,
+ collapsedRowCount = COLLAPSED_SECTION_ROW_COUNT,
+ collapsedRowCountById,
+ }: CollapsedLayoutOptions,
): TPlacement[] => {
if (!Number.isFinite(collapsedRowCount) || collapsedRowCount <= 0) {
throw new RangeError("collapsedRowCount must be positive and finite");
}
const normalized = placements.map((placement) => normalizeGridPlacement(placement, columnCount));
- const displayPlacements = normalized.map((placement) =>
- collapsedItemIds.has(placement.id)
- ? {
- ...placement,
- h: collapsedRowCount,
- }
- : placement,
- );
-
- return reflowCollapsedDisplayLayout(normalized, displayPlacements, collapsedItemIds, collapsedRowCount);
+ const displayPlacements = normalized.map((placement) => {
+ if (!collapsedItemIds.has(placement.id)) return placement;
+ const height = collapsedRowCountById?.get(placement.id) ?? collapsedRowCount;
+ if (!Number.isFinite(height) || height <= 0) {
+ throw new RangeError("collapsedRowCount must be positive and finite");
+ }
+ return { ...placement, h: height };
+ });
+
+ return reflowCollapsedDisplayLayout(normalized, displayPlacements, collapsedItemIds);
};
/**
@@ -122,7 +128,6 @@ const reflowCollapsedDisplayLayout = <TPlacement extends GridPlacement>(
expandedPlacements: readonly TPlacement[],
displayPlacements: readonly TPlacement[],
collapsedItemIds: ReadonlySet<string>,
- collapsedRowCount: number,
): TPlacement[] => {
assertUniqueIds(expandedPlacements);
const displayById = new Map(displayPlacements.map((placement) => [placement.id, placement]));
@@ -131,7 +136,7 @@ const reflowCollapsedDisplayLayout = <TPlacement extends GridPlacement>(
for (const expandedPlacement of expandedPlacements.toSorted(comparePlacements)) {
const candidate = getRequiredPlacement(displayById, expandedPlacement.id);
- const verticalShift = getCollapsedVerticalShift(expandedPlacement, collapsedPlacements, collapsedRowCount);
+ const verticalShift = getCollapsedVerticalShift(expandedPlacement, collapsedPlacements, displayById);
placed.push({
...candidate,
y: findFirstAvailableRowAtOrAfter(candidate, placed, Math.max(0, candidate.y - verticalShift)),
@@ -145,7 +150,7 @@ const reflowCollapsedDisplayLayout = <TPlacement extends GridPlacement>(
const getCollapsedVerticalShift = (
candidate: GridPlacement,
collapsedPlacements: readonly GridPlacement[],
- collapsedRowCount: number,
+ displayById: ReadonlyMap<string, GridPlacement>,
) => {
const removedIntervals = collapsedPlacements
.filter(
@@ -154,7 +159,10 @@ const getCollapsedVerticalShift = (
collapsed.y + collapsed.h <= candidate.y &&
doGridPlacementsOverlapHorizontally(candidate, collapsed),
)
- .map((collapsed) => ({ start: collapsed.y + collapsedRowCount, end: collapsed.y + collapsed.h }))
+ .map((collapsed) => ({
+ start: collapsed.y + getRequiredPlacement(displayById, collapsed.id).h,
+ end: collapsed.y + collapsed.h,
+ }))
.toSorted((first, second) => first.start - second.start || first.end - second.end);
let shift = 0;
diff --git a/apps/nextjs/src/components/board/sections/container-section.tsx b/apps/nextjs/src/components/board/sections/container-section.tsx
index 9a93a9f32..065da94fc 100644
--- a/apps/nextjs/src/components/board/sections/container-section.tsx
+++ b/apps/nextjs/src/components/board/sections/container-section.tsx
@@ -1,3 +1,4 @@
+import type { PointerEvent, MouseEvent } from "react";
import { createContext, useContext, useRef } from "react";
import dynamic from "next/dynamic";
import { ActionIcon, Badge, Box, Button, Card } from "@mantine/core";
@@ -10,7 +11,7 @@ import { getRootSectionLane } from "@homarr/definitions";
import { useI18n } from "@homarr/translation/client";
import type { ContainerSectionItem } from "~/app/[locale]/boards/_types";
-import { COLLAPSED_SECTION_ROW_COUNT } from "~/components/board/layout";
+import { CONTAINER_HEADER_HEIGHT } from "~/components/board/layout";
import { SectionGrid } from "./grid/section-grid";
import { useSectionCollapse } from "./section-collapse";
import { useSectionContext } from "./section-context";
@@ -48,6 +49,7 @@ export const BoardContainerSection = ({ section }: Props) => {
const t = useI18n("section.container");
const tSection = useI18n("section");
const options = section.options;
+ const hasHeader = options.collapsible && options.showLabel;
const { open: openAllInNewTabs, isLoading: areAppsLoading } = useOpenSectionApps(
section.id,
options.showOpenAll && !isEditMode,
@@ -58,7 +60,11 @@ export const BoardContainerSection = ({ section }: Props) => {
});
const label = options.title.trim() || t("untitled");
const contentId = `board-container-${section.id}-content`;
- const menuPosition = { right: getBoundedMenuOffset(menuRightOffset), top: getBoundedMenuOffset(menuTopOffset) };
+ let menuTop = getBoundedMenuOffset(menuTopOffset);
+ if (hasHeader) {
+ menuTop = "calc(var(--container-header-height) / 2 - 12px * var(--mantine-scale))";
+ }
+ const menuPosition = { right: getBoundedMenuOffset(menuRightOffset), top: menuTop };
const labelTop = "calc(var(--mantine-spacing-xs) * -1)";
const labelLeft = 8;
let labelRight = 8;
@@ -89,6 +95,29 @@ export const BoardContainerSection = ({ section }: Props) => {
) : (
<IconChevronUp size="var(--mantine-font-size-md)" />
);
+ const toggleHandlers = {
+ onPointerDown: (event: PointerEvent<HTMLButtonElement>) => {
+ togglePointer.current = { x: event.clientX, y: event.clientY, moved: false };
+ },
+ onPointerMove: (event: PointerEvent<HTMLButtonElement>) => {
+ const pointer = togglePointer.current;
+ if (!pointer || event.buttons === 0) return;
+ if (Math.hypot(event.clientX - pointer.x, event.clientY - pointer.y) > 5) {
+ pointer.moved = true;
+ }
+ },
+ onPointerCancel: () => {
+ togglePointer.current = null;
+ },
+ onClick: (event: MouseEvent<HTMLButtonElement>) => {
+ if (event.detail > 0 && togglePointer.current?.moved) return;
+ toggle();
+ },
+ };
+ let headerActionInset = "0px";
+ if (isEditMode) {
+ headerActionInset = `calc(${menuPosition.right} + 28px * var(--mantine-scale))`;
+ }
return (
<Box
@@ -105,7 +134,8 @@ export const BoardContainerSection = ({ section }: Props) => {
classes.itemCard,
classes.containerCard,
options.customCssClasses.join(" "),
- isVisuallyCollapsed && classes.collapsedContainerCard,
+ isVisuallyCollapsed && !hasHeader && classes.collapsedContainerCard,
+ hasHeader && classes.labeledContainerCard,
)}
w="100%"
h="100%"
@@ -115,12 +145,32 @@ export const BoardContainerSection = ({ section }: Props) => {
overflow: "visible",
"--opacity": board.opacity / 100,
"--container-border-color": options.borderColor || undefined,
+ "--container-action-inset": headerActionInset,
+ "--container-header-height": `calc(${CONTAINER_HEADER_HEIGHT}px * var(--board-canvas-ui-scale, 1))`,
},
}}
radius={board.itemRadius}
p={0}
>
- {options.collapsible && (
+ {hasHeader && (
+ <div className={classes.containerHeader} data-board-container-header>
+ <button
+ type="button"
+ className={classes.containerHeaderToggle}
+ data-board-container-label
+ data-board-container-collapsed-control={isVisuallyCollapsed ? "true" : undefined}
+ {...toggleHandlers}
+ aria-expanded={!isVisuallyCollapsed}
+ aria-controls={contentId}
+ aria-label={`${t(isVisuallyCollapsed ? "action.expand" : "action.collapse")}: ${label}`}
+ title={label}
+ >
+ <span className={classes.containerHeaderTitle}>{label}</span>
+ <span className={classes.containerHeaderIcon}>{toggleIcon}</span>
+ </button>
+ </div>
+ )}
+ {options.collapsible && !hasHeader && (
<Button
className={classes.containerToggle}
pos="absolute"
@@ -130,33 +180,15 @@ export const BoardContainerSection = ({ section }: Props) => {
pe={collapsedLabelPaddingRight}
radius="sm"
variant="default"
- justify={options.showLabel ? "flex-start" : "center"}
- leftSection={options.showLabel && toggleIcon}
- onPointerDown={(event) => {
- togglePointer.current = { x: event.clientX, y: event.clientY, moved: false };
- }}
- onPointerMove={(event) => {
- const pointer = togglePointer.current;
- if (!pointer || event.buttons === 0) return;
- if (Math.hypot(event.clientX - pointer.x, event.clientY - pointer.y) > 5) {
- pointer.moved = true;
- }
- }}
- onPointerCancel={() => {
- togglePointer.current = null;
- }}
- onClick={(event) => {
- if (event.detail > 0 && togglePointer.current?.moved) return;
- toggle();
- }}
+ justify="center"
+ {...toggleHandlers}
aria-expanded={!isVisuallyCollapsed}
aria-controls={contentId}
aria-label={`${t(isVisuallyCollapsed ? "action.expand" : "action.collapse")}: ${label}`}
data-board-container-collapsed-control={isVisuallyCollapsed ? "true" : undefined}
data-board-container-label
- title={options.showLabel ? label : undefined}
>
- {options.showLabel ? label : toggleIcon}
+ {toggleIcon}
</Button>
)}
{!isVisuallyCollapsed && !options.collapsible && options.showLabel && options.title && (
@@ -212,7 +244,7 @@ export const BoardContainerSection = ({ section }: Props) => {
columnCount={section.width}
containerInlineInsetCount={containerInlineInsetCount}
requestedRowCount={section.height}
- viewportRowCountOverride={isVisuallyCollapsed ? COLLAPSED_SECTION_ROW_COUNT : undefined}
+ viewportRowCountOverride={isVisuallyCollapsed ? section.height : undefined}
label={label}
/>
</ContainerDepthContext>
diff --git a/apps/nextjs/src/components/board/sections/grid/section-grid.tsx b/apps/nextjs/src/components/board/sections/grid/section-grid.tsx
index 2ef3b98be..cdf397597 100644
--- a/apps/nextjs/src/components/board/sections/grid/section-grid.tsx
+++ b/apps/nextjs/src/components/board/sections/grid/section-grid.tsx
@@ -11,11 +11,13 @@ import { useEditMode } from "@homarr/boards/edit-mode";
import type { ContainerSectionItem, Section } from "~/app/[locale]/boards/_types";
import {
getCollapsedDisplayLayout,
+ CONTAINER_HEADER_HEIGHT,
getEditableCanvasAttributes,
getGridRowCountForVisualHeight,
getLayoutRowCount,
getLogicalGridSize,
getReadonlyCanvasAttributes,
+ LOGICAL_GRID_PITCH,
normalizeGridPlacement,
} from "~/components/board/layout";
import { calculateBoardUiScale, useBoardCanvasScale } from "~/components/board/layout/scaled-board-canvas";
@@ -58,6 +60,7 @@ export const SectionGrid = ({
const canvasScale = useBoardCanvasScale();
const parentContentScale = useContext(GridContentScaleContext);
const parentRowScale = useContext(GridRowScaleContext);
+ const [collapsedRowsPerPixel, setCollapsedRowsPerPixel] = useState<number>();
const editorRuntimeStatus = useGridEditorRuntimeStatus();
const editorRegistry = useGridEditorRegistry();
const editorHostRef = useRef<HTMLDivElement>(null);
@@ -65,6 +68,9 @@ export const SectionGrid = ({
const board = useRequiredBoard();
const currentLayoutId = useCurrentLayout();
const { items, innerSections } = useSectionItems(section.id);
+ const hasLabeledCollapsibleChildren = innerSections.some(
+ (child) => child.options.collapsible && child.options.showLabel,
+ );
const { announce, integrations } = useBoardGridPortalHost();
const collapsedSectionIds = useCollapsedSectionIds();
const expandSectionsForEditing = useExpandSectionsForEditing();
@@ -117,14 +123,29 @@ export const SectionGrid = ({
),
[collapsedSectionIds, collapsibleSectionIds, placements],
);
+ const hasCollapsedHeader = innerSections.some((child) => child.options.showLabel && directCollapsedIds.has(child.id));
const displayPlacements = useMemo(() => {
if (directCollapsedIds.size === 0) return placements;
+ let collapsedRowCountById: ReadonlyMap<string, number> | undefined;
+ if (collapsedRowsPerPixel !== undefined) {
+ const headerHeight = CONTAINER_HEADER_HEIGHT * calculateBoardUiScale(canvasScale) * canvasScale;
+ collapsedRowCountById = new Map(
+ innerSections
+ .filter((child) => child.options.collapsible && child.options.showLabel)
+ .map((child) => {
+ let topInset = CONTAINER_CARD_INSET;
+ if (railPlacement !== "main" && child.yOffset === 0) topInset = 0;
+ return [child.id, (headerHeight + topInset + 10) * collapsedRowsPerPixel];
+ }),
+ );
+ }
return getCollapsedDisplayLayout(placements, {
columnCount,
collapsedItemIds: directCollapsedIds,
+ collapsedRowCountById,
});
- }, [columnCount, directCollapsedIds, placements]);
+ }, [canvasScale, columnCount, directCollapsedIds, innerSections, placements, collapsedRowsPerPixel, railPlacement]);
const placementById = useMemo(
() => new Map(displayPlacements.map((placement) => [placement.id, placement])),
@@ -175,19 +196,27 @@ export const SectionGrid = ({
allocatedViewportHeight *= parentRowScale;
}
const logicalWidth = Math.max(1, fullGridWidth - outerCardInlineInset);
+ const hasContainerHeader = section.kind === "container" && section.options.collapsible && section.options.showLabel;
+ let headerInset = 0;
+ if (hasContainerHeader && !collapsedSectionIds.has(section.id)) {
+ headerInset = (CONTAINER_HEADER_HEIGHT * calculateBoardUiScale(canvasScale)) / parentContentScale;
+ }
let nestedHeaderInset = 0;
if (
section.kind === "container" &&
(section.options.collapsible || (section.options.showLabel && section.options.title)) &&
innerSections.some(
- (child) => child.yOffset === 0 && (child.options.collapsible || (child.options.showLabel && child.options.title)),
+ (child) =>
+ child.yOffset === 0 &&
+ (child.options.collapsible || (child.options.showLabel && child.options.title)) &&
+ (!hasContainerHeader || !child.options.collapsible || !child.options.showLabel),
)
) {
- // Separate floating parent/child headers while retaining the persisted cell footprint.
+ // Keep the extra gap whenever either adjacent header still floats over its border.
nestedHeaderInset = (20 * calculateBoardUiScale(canvasScale)) / effectiveCanvasScale;
}
nestedHeaderInset = Math.min(nestedHeaderInset, Math.max(0, allocatedViewportHeight - outerCardInset - 1));
- const viewportHeight = Math.max(1, allocatedViewportHeight - outerCardInset - nestedHeaderInset);
+ const viewportHeight = Math.max(1, allocatedViewportHeight - outerCardInset - nestedHeaderInset - headerInset);
// Fit columns to the card width. Rows fit the available height independently
// without creating horizontal gutters or distorting text and icons.
let containerContentScale = 1;
@@ -195,7 +224,8 @@ export const SectionGrid = ({
if (section.kind === "container" && fullGridWidth > 0 && fullViewportHeight > 0) {
containerContentScale = Math.max(0.01, Math.min(logicalWidth / fullGridWidth, 1));
rowScale = Math.max(0.01, viewportHeight / (fullViewportHeight * containerContentScale));
- } else if (isRail && railLogicalHeight > 0 && rowCount <= railViewportRowCount) {
+ } else if (isRail && railLogicalHeight > 0 && rowCount <= railViewportRowCount && !hasCollapsedHeader) {
+ // Keep fixed-height collapsed headers out of the rail's fill compression.
rowScale = viewportHeight / fullViewportHeight;
}
const contentScale = parentContentScale * containerContentScale;
@@ -207,6 +237,11 @@ export const SectionGrid = ({
// is a circular reference - CSS invalidates the whole group rather than using "the old value",
// silently breaking every icon/text/custom-CSS size that compensates off it for descendants.
const combinedUiScale = calculateBoardUiScale(canvasScale) / contentScale;
+ useLayoutEffect(() => {
+ if (!hasLabeledCollapsibleChildren) return;
+ // Convert the fixed header and visual insets into this grid's row units.
+ setCollapsedRowsPerPixel(1 / (effectiveContentScale * LOGICAL_GRID_PITCH * rowScale));
+ }, [effectiveContentScale, hasLabeledCollapsibleChildren, rowScale]);
// A collapsed container's compact coordinates are display-only. Its own
// nested grid stays inactive until an explicit edit interaction expands it.
const isInteractionDisabled = section.kind === "container" && collapsedSectionIds.has(section.id);
diff --git a/apps/nextjs/src/components/board/sections/item.module.css b/apps/nextjs/src/components/board/sections/item.module.css
index 8fac711ce..e8a82bb64 100644
--- a/apps/nextjs/src/components/board/sections/item.module.css
+++ b/apps/nextjs/src/components/board/sections/item.module.css
@@ -45,18 +45,102 @@
border-color: var(--border-color) !important;
}
-.containerToggle :global(.mantine-Button-inner) {
- width: 100%;
+.labeledContainerCard[data-board-container-collapsed="true"] {
+ height: min(var(--container-header-height), 100%) !important;
+}
+
+.containerHeader {
+ position: absolute;
+ inset-block-start: 0;
+ inset-inline-start: 0;
+ inset-inline-end: 0;
+ z-index: 9;
+ height: var(--container-header-height);
min-width: 0;
+ border-radius: inherit;
+ border-end-start-radius: 0;
+ border-end-end-radius: 0;
+ box-shadow: inset 0 calc(-1px * var(--board-canvas-ui-scale, 1)) 0
+ color-mix(in srgb, var(--border-color) 65%, transparent);
+}
+
+.labeledContainerCard[data-board-container-collapsed="true"] > .containerHeader {
+ max-height: 100%;
+ border-radius: inherit;
+ box-shadow: none;
+}
+
+.containerHeaderToggle {
+ display: flex;
+ align-items: center;
+ gap: calc(12px * var(--board-canvas-ui-scale, 1));
+ width: calc(100% - var(--container-action-inset, 0px));
+ height: 100%;
+ min-width: 0;
+ padding: 0 calc(16px * var(--board-canvas-ui-scale, 1));
+ overflow: hidden;
+ border: 0;
+ border-radius: inherit;
+ background: transparent;
+ color: var(--mantine-color-text);
+ font: inherit;
+ text-align: start;
+ cursor: pointer;
+ touch-action: manipulation;
+ transition: background-color 120ms ease;
+}
+
+.containerHeaderToggle:hover {
+ background-color: color-mix(in srgb, var(--mantine-color-text) 4%, transparent);
+}
+
+.containerHeaderToggle:focus-visible {
+ outline: calc(2px * var(--board-canvas-ui-scale, 1)) solid var(--mantine-primary-color-filled);
+ outline-offset: calc(-2px * var(--board-canvas-ui-scale, 1));
}
-.containerToggle :global(.mantine-Button-label) {
+.containerHeaderTitle {
min-width: 0;
overflow: hidden;
+ font-size: var(--mantine-font-size-sm);
+ font-weight: 600;
+ line-height: 1.3;
text-overflow: ellipsis;
white-space: nowrap;
}
+.containerHeaderIcon {
+ display: flex;
+ flex-shrink: 0;
+ margin-inline-start: auto;
+ color: var(--mantine-color-dimmed);
+}
+
+.labeledContainerCard:has(> .containerAction) > .containerHeader .containerHeaderIcon {
+ padding-inline-start: calc(36px * var(--board-canvas-ui-scale, 1));
+}
+
+.containerHeaderIcon > svg {
+ width: calc(18px * var(--board-canvas-ui-scale, 1));
+ height: calc(18px * var(--board-canvas-ui-scale, 1));
+}
+
+.labeledContainerCard > .containerBody {
+ box-sizing: border-box;
+ padding-block-start: var(--container-header-height);
+}
+
+.labeledContainerCard[data-board-container-collapsed="true"] > .containerBody {
+ padding: 0;
+}
+
+.labeledContainerCard > .containerAction {
+ right: auto !important;
+ inset-inline-end: calc(46px * var(--board-canvas-ui-scale, 1)) !important;
+ top: calc(var(--container-header-height) / 2) !important;
+ transform: translateY(-50%) !important;
+}
+
.containerLabel,
.containerAction {
background-color: var(--background-color) !important;
@@ -93,6 +177,7 @@
}
@media (prefers-reduced-motion: reduce) {
+ .containerHeaderToggle,
.containerBody,
.containerBody[data-collapsed="true"] {
transition: none;