Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

fix: stabilize responsive navigation and database toolbar (#134)

Rebertt Rodriguesf2f7a9294b5a
diff --git a/frontend/src/hooks/__tests__/useOverflowItems.test.mjs b/frontend/src/hooks/__tests__/useOverflowItems.test.mjs
index 8f3ef3ab..0b731823 100644
--- a/frontend/src/hooks/__tests__/useOverflowItems.test.mjs
+++ b/frontend/src/hooks/__tests__/useOverflowItems.test.mjs
@@ -1,7 +1,42 @@
import assert from 'node:assert/strict';
import test from 'node:test';
-import { sanitizeOverflowIndices } from '../useOverflowItems.js';
+import { measureNaturalWidths, sanitizeOverflowIndices } from '../useOverflowItems.js';
+
+test('measures stylesheet-hidden items without leaving them visible', () => {
+ const visible = {
+ style: { display: '' },
+ computedDisplay: 'inline-flex',
+ get offsetWidth() { return 96; },
+ };
+ const hiddenByClass = {
+ style: { display: '' },
+ computedDisplay: 'none',
+ get offsetWidth() { return this.style.display === 'inline-flex' ? 128 : 0; },
+ };
+ const hiddenInline = {
+ style: { display: 'none' },
+ computedDisplay: 'none',
+ get offsetWidth() { return this.style.display === 'inline-flex' ? 84 : 0; },
+ };
+ const originalGetComputedStyle = globalThis.getComputedStyle;
+ globalThis.getComputedStyle = (element) => ({
+ display: element.style.display === 'inline-flex'
+ ? 'inline-flex'
+ : element.computedDisplay,
+ });
+
+ try {
+ assert.deepEqual(
+ measureNaturalWidths([visible, hiddenByClass, hiddenInline, null]),
+ [96, 128, 84, 0]
+ );
+ assert.equal(hiddenByClass.style.display, '');
+ assert.equal(hiddenInline.style.display, 'none');
+ } finally {
+ globalThis.getComputedStyle = originalGetComputedStyle;
+ }
+});
test('drops stale overflow indexes when a route switches to fewer tabs', () => {
assert.deepEqual(sanitizeOverflowIndices([2, 4, 7, 9], 4), [2]);
diff --git a/frontend/src/hooks/useOverflowItems.js b/frontend/src/hooks/useOverflowItems.js
index 3856931d..1b37eef7 100644
--- a/frontend/src/hooks/useOverflowItems.js
+++ b/frontend/src/hooks/useOverflowItems.js
@@ -6,6 +6,37 @@ function arraysEqual(a, b) {
return true;
}
+/**
+ * Measure overflow items at their natural width without leaving collapsed
+ * items visible. CSS-hidden consumers (for example PageTopbar's `is-hidden`
+ * class) and inline-hidden consumers both need an explicit display override;
+ * clearing only the inline declaration does not override a stylesheet rule.
+ *
+ * DOM writes are applied before any width reads to avoid a layout flush for
+ * every item in the strip.
+ */
+export function measureNaturalWidths(items) {
+ const elements = Array.isArray(items) ? items : [];
+ const restore = [];
+
+ for (const element of elements) {
+ if (!element || getComputedStyle(element).display !== 'none') continue;
+ restore.push([element, element.style.display]);
+ element.style.display = 'inline-flex';
+ }
+
+ let widths;
+ try {
+ widths = elements.map((element) => element?.offsetWidth || 0);
+ } finally {
+ for (const [element, display] of restore) {
+ element.style.display = display;
+ }
+ }
+
+ return widths;
+}
+
/**
* Keep overflow state safe while a shared tab layout switches to a shorter
* item list. Effects recompute after render, so consumers must not receive
@@ -62,14 +93,7 @@ export function useOverflowItems({ count, itemRefs: externalItemRefs, gap = 8, m
if (containerWidth === 0) return;
// Measure each item's natural width (briefly un-hiding collapsed ones).
- const widths = itemRefs.current.map((el) => {
- if (!el) return 0;
- const wasHidden = el.style.display === 'none';
- if (wasHidden) el.style.display = '';
- const w = el.offsetWidth;
- if (wasHidden) el.style.display = 'none';
- return w;
- });
+ const widths = measureNaturalWidths(itemRefs.current);
const activeIndex = getActiveIndex();
const actualMoreWidth = moreBtnRef.current?.offsetWidth || moreWidth;
diff --git a/frontend/src/styles/components/_design-system.scss b/frontend/src/styles/components/_design-system.scss
index e23cecc1..6a55a973 100644
--- a/frontend/src/styles/components/_design-system.scss
+++ b/frontend/src/styles/components/_design-system.scss
@@ -1256,7 +1256,10 @@ $sk-tones: ('accent', 'green', 'cyan', 'amber', 'red', 'violet');
// Overflow ("More") trigger — a tab-styled button that never collapses.
&__more {
flex-shrink: 0;
+ appearance: none;
+ background: transparent;
border: none;
+ color: inherit;
font: inherit;
cursor: pointer;
&[data-state="open"] { background: var(--surface-hover); color: var(--text); }
@@ -1264,6 +1267,22 @@ $sk-tones: ('accent', 'green', 'cyan', 'amber', 'red', 'violet');
@media (max-width: 768px) {
flex-wrap: wrap;
+ &__actions {
+ order: 2;
+ width: 100%;
+ min-width: 0;
+ justify-content: flex-start;
+ overflow-x: auto;
+ overflow-y: hidden;
+ scrollbar-width: none;
+ -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 28px), transparent 100%);
+ mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 28px), transparent 100%);
+
+ > *,
+ > .sk-topbar__chrome > * { flex-shrink: 0; }
+
+ &::-webkit-scrollbar { display: none; }
+ }
&__tabs { order: 3; width: 100%; margin-left: 0; justify-content: flex-start; }
}
}
diff --git a/frontend/src/styles/components/_global-statusbar.scss b/frontend/src/styles/components/_global-statusbar.scss
index 0c7de502..e347c770 100644
--- a/frontend/src/styles/components/_global-statusbar.scss
+++ b/frontend/src/styles/components/_global-statusbar.scss
@@ -542,6 +542,16 @@
.shell-panel,
.operations-dock.operations-dock--statusbar {
inset-inline-start: $sidebar-rail-width;
+ transition: inset-inline-start 0.18s $ease-out-quint;
+ }
+
+ .sidebar:hover,
+ .sidebar:focus-within {
+ ~ .global-statusbar,
+ ~ .shell-panel,
+ ~ .operations-dock.operations-dock--statusbar {
+ inset-inline-start: $sidebar-width;
+ }
}
}
@@ -625,4 +635,10 @@
@media (prefers-reduced-motion: reduce) {
.shell-panel,
.operations-dock.operations-dock--statusbar .operations-dock__panel { animation: none; }
+
+ [data-layout='rail'] {
+ .global-statusbar,
+ .shell-panel,
+ .operations-dock.operations-dock--statusbar { transition: none; }
+ }
}
diff --git a/frontend/src/styles/pages/_databases.scss b/frontend/src/styles/pages/_databases.scss
index 800adf79..05e00b08 100644
--- a/frontend/src/styles/pages/_databases.scss
+++ b/frontend/src/styles/pages/_databases.scss
@@ -117,6 +117,24 @@ $dbx-sqlite: #3d8fd1;
svg { color: $accent-primary; }
}
+ @media (max-width: $breakpoint-sm) {
+ .dbx-toolbar {
+ justify-content: flex-start;
+ overflow-x: auto;
+ overflow-y: hidden;
+ scrollbar-width: none;
+ -webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 28px), transparent 100%);
+ mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 28px), transparent 100%);
+
+ &::-webkit-scrollbar { display: none; }
+ }
+
+ .dbx-toolbar-left,
+ .dbx-toolbar-right { flex-shrink: 0; }
+
+ .dbx-title { white-space: nowrap; }
+ }
+
// ─── New menu ─────────────────────────────────────────
.dbx-new { position: relative; }