Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: keep theme chooser visible in short viewports (#9882)
Adam Eivyc3c698e3dd53
diff --git a/client/src/components/ThemeSwitcher.browser.test.js b/client/src/components/ThemeSwitcher.browser.test.jsnew file mode 100644index 0000000000..b09d9dc7aa--- /dev/null+++ b/client/src/components/ThemeSwitcher.browser.test.js@@ -0,0 +1,142 @@+// @vitest-environment node+import { afterAll, beforeAll, describe, expect, it } from 'vitest';+import { existsSync } from 'node:fs';+import { mkdtemp, rm } from 'node:fs/promises';+import { createRequire } from 'node:module';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { fileURLToPath } from 'node:url';+import { createServer } from 'vite';+import react from '@vitejs/plugin-react';+import { THEME_IDS } from '../themes/portosThemes.js';++const require = createRequire(import.meta.url);+const { chromium } = require(require.resolve('playwright-core', { paths: [+ fileURLToPath(new URL('../..', import.meta.url)),+ fileURLToPath(new URL('../../../server', import.meta.url)),+] }));+const chrome = [process.env.CHROME_PATH, chromium.executablePath(),+ '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',+ '/usr/bin/google-chrome', '/usr/bin/chromium', '/usr/bin/chromium-browser',+].find(path => path && existsSync(path));++describe.skipIf(!chrome)('theme chooser in short viewports', () => {+ let server;+ let browser;+ let browserTemp;+ let origin;++ beforeAll(async () => {+ browserTemp = await mkdtemp(join(tmpdir(), 'theme-switcher-chrome-'));+ server = await createServer({+ configFile: false,+ cacheDir: join(browserTemp, 'vite-cache'),+ root: fileURLToPath(new URL('../..', import.meta.url)),+ plugins: [react(), {+ name: 'theme-switcher-browser-fixture',+ resolveId(id) { if (id === '/theme-switcher-fixture.jsx') return '\0theme-switcher-fixture.jsx'; },+ load(id) {+ if (id !== '\0theme-switcher-fixture.jsx') return;+ return `+ import React from 'react';+ import { createRoot } from 'react-dom/client';+ import { ThemeProvider } from '/src/components/ThemeContext.jsx';+ import ThemeSwitcher from '/src/components/ThemeSwitcher.jsx';+ import '/src/index.css';+ createRoot(document.getElementById('root')).render(+ React.createElement(ThemeProvider, null,+ React.createElement(React.Fragment, null,+ React.createElement('button', { id: 'before' }, 'Before'),+ React.createElement('div', { id: 'trigger-row' }, React.createElement(ThemeSwitcher)),+ React.createElement('button', { id: 'after' }, 'After')))+ );+ `;+ },+ configureServer(vite) {+ vite.middlewares.use('/theme-switcher-test', async (_req, res) => {+ res.setHeader('Content-Type', 'text/html');+ res.end(await vite.transformIndexHtml('/theme-switcher-test',+ '<div id="root"></div><script type="module" src="/theme-switcher-fixture.jsx"></script>'));+ });+ },+ }],+ server: { host: '127.0.0.1', port: 0 },+ });+ await server.listen();+ origin = server.resolvedUrls.local[0];+ browser = await chromium.launch({ executablePath: chrome, headless: true, args: ['--mute-audio'],+ env: { ...process.env, TMPDIR: browserTemp, TMP: browserTemp, TEMP: browserTemp },+ });+ }, 60000);++ afterAll(async () => {+ try {+ await browser?.close();+ } finally {+ await server?.close();+ if (browserTemp) await rm(browserTemp, { recursive: true, force: true });+ }+ });++ it.each([{ width: 640, height: 400 }, { width: 360, height: 400 }, { width: 1280, height: 800 }])(+ 'keeps selected and keyboard-focused themes visible at $width×$height', async ({ width, height }) => {+ const page = await browser.newPage({ viewport: { width, height } });+ try {+ await page.addInitScript(themeId => localStorage.setItem('portos-theme', themeId), THEME_IDS.at(-1));+ await page.route('**/api/**', route => route.fulfill({ status: 200, contentType: 'application/json', body: '{}' }));+ await page.goto(`${origin}theme-switcher-test`);+ await page.addStyleTag({ content: '#trigger-row{position:absolute;top:340px;left:16px}' });+ const trigger = page.getByRole('button', { name: /Switch theme/ });+ const menu = page.getByRole('menu', { name: 'Interface theme' });+ await trigger.focus();+ await page.keyboard.press('Enter');+ await menu.waitFor();+ const items = page.getByRole('menuitemradio');+ expect(await items.count()).toBe(THEME_IDS.length);+ expect(await items.last().getAttribute('aria-checked')).toBe('true');++ const expectFocusVisible = async () => {+ const bounds = await page.evaluate(() => {+ const menuElement = document.querySelector('[role="menu"]');+ const item = document.activeElement;+ const menuRect = menuElement.getBoundingClientRect();+ const itemRect = item.getBoundingClientRect();+ return {+ left: menuRect.left, top: menuRect.top, right: menuRect.right, bottom: menuRect.bottom,+ clientTop: menuElement.clientTop, clientHeight: menuElement.clientHeight,+ scrollHeight: menuElement.scrollHeight,+ itemTop: itemRect.top, itemBottom: itemRect.bottom,+ viewportWidth: innerWidth, viewportHeight: innerHeight,+ };+ });+ expect(bounds.left).toBeGreaterThanOrEqual(8);+ expect(bounds.right).toBeLessThanOrEqual(bounds.viewportWidth - 8);+ expect(bounds.top).toBeGreaterThanOrEqual(8);+ expect(bounds.bottom).toBeLessThanOrEqual(bounds.viewportHeight - 8);+ expect(bounds.scrollHeight).toBeGreaterThan(bounds.clientHeight);+ expect(bounds.itemTop).toBeGreaterThanOrEqual(bounds.top + bounds.clientTop);+ expect(bounds.itemBottom).toBeLessThanOrEqual(bounds.top + bounds.clientTop + bounds.clientHeight);+ };++ await expectFocusVisible();+ await page.keyboard.press('ArrowUp');+ await expectFocusVisible();+ await page.keyboard.press('Home');+ await expectFocusVisible();+ await page.keyboard.press('End');+ await expectFocusVisible();+ await page.keyboard.press('Escape');+ expect(await menu.count()).toBe(0);+ expect(await trigger.evaluate(element => element === document.activeElement)).toBe(true);++ await page.keyboard.press('Enter');+ await page.getByRole('menu').waitFor();+ await page.keyboard.press('Tab');+ expect(await page.getByRole('menu').count()).toBe(0);+ expect(await page.locator('#after').evaluate(element => element === document.activeElement)).toBe(true);+ } finally {+ await page.close();+ }+ },+ );+});diff --git a/client/src/components/ThemeSwitcher.jsx b/client/src/components/ThemeSwitcher.jsxindex 0600ba1961..24ba4a561d 100644--- a/client/src/components/ThemeSwitcher.jsx+++ b/client/src/components/ThemeSwitcher.jsx@@ -19,7 +19,7 @@ export default function ThemeSwitcher({ position = 'above', className = '' }) {triggerRef,popoverRef: menuRef,style: menuStyle,- } = usePopoverPosition({ open, width: MENU_WIDTH, minWidth: 180, gap: 8, position });+ } = usePopoverPosition({ open, width: MENU_WIDTH, minWidth: 180, gap: 8, position, constrainHeight: true });const close = useCallback((refocus) => {setOpen(false);@@ -108,11 +108,12 @@ export default function ThemeSwitcher({ position = 'above', className = '' }) {role="menu"aria-label="Interface theme"onKeyDown={handleMenuKeyDown}- className="fixed max-w-[calc(100vw-1rem)] bg-port-card border border-port-border rounded-xl shadow-xl z-[100] p-2"+ className="fixed max-w-[calc(100vw-1rem)] overflow-y-auto bg-port-card border border-port-border rounded-xl shadow-xl z-[100] p-2"style={{left: menuStyle?.left ?? `${VIEWPORT_PADDING}px`,top: menuStyle?.top ?? `${VIEWPORT_PADDING}px`,width: menuStyle?.width ?? `${MENU_WIDTH}px`,+ maxHeight: menuStyle?.maxHeight,visibility: menuStyle ? 'visible' : 'hidden',}}>diff --git a/client/src/components/ThemeSwitcher.test.jsx b/client/src/components/ThemeSwitcher.test.jsxindex bd13b0fbac..712ae6549b 100644--- a/client/src/components/ThemeSwitcher.test.jsx+++ b/client/src/components/ThemeSwitcher.test.jsx@@ -2,48 +2,38 @@ import { fireEvent, render, screen, within } from '@testing-library/react';import { describe, expect, it, vi } from 'vitest';import ThemeSwitcher from './ThemeSwitcher';-vi.mock('./ThemeContext', () => ({- useThemeContext: () => ({- themeId: 'classic-midnight',- theme: { label: 'Classic Midnight' },- themeList: [- {- id: 'classic-midnight',- label: 'Classic Midnight',- shortLabel: 'Classic',- density: 'comfortable',- family: 'classic',- accent: '#2563eb',- },- {- id: 'blueprint-day',- label: 'Blueprint Day',- shortLabel: 'Blueprint',- density: 'compact',- family: 'blueprint',- accent: '#0ea5e9',- },- ],- setTheme: vi.fn(),- }),-}));+vi.mock('./ThemeContext', async () => {+ const { THEME_LIST } = await import('../themes/portosThemes');+ return {+ useThemeContext: () => ({+ themeId: 'classic-midnight',+ theme: { label: 'Classic Midnight' },+ themeList: THEME_LIST,+ setTheme: vi.fn(),+ }),+ };+});describe('ThemeSwitcher', () => {- it('exposes the current theme through accessible menu radio state', () => {+ it('exposes the current theme in the full, height-constrained keyboard menu', () => {render(<ThemeSwitcher />);fireEvent.click(screen.getByRole('button', { name: /Switch theme/ }));const menu = screen.getByRole('menu', { name: 'Interface theme' });- const active = within(menu).getByRole('menuitemradio', { name: /Classic Midnight/ });- const inactive = within(menu).getByRole('menuitemradio', { name: /Blueprint Day/ });+ const items = within(menu).getAllByRole('menuitemradio');+ const active = items[0];+ const next = items[1];+ expect(items.length).toBeGreaterThanOrEqual(10);expect(menu).toHaveStyle({ visibility: 'visible' });+ expect(menu.className).toContain('overflow-y-auto');+ expect(menu.style.maxHeight).toMatch(/^\d+px$/);expect(active).toHaveAttribute('aria-checked', 'true');- expect(inactive).toHaveAttribute('aria-checked', 'false');+ expect(next).toHaveAttribute('aria-checked', 'false');expect(active).toHaveFocus();fireEvent.keyDown(active, { key: 'ArrowDown' });- expect(inactive).toHaveFocus();- fireEvent.keyDown(inactive, { key: 'ArrowUp' });+ expect(next).toHaveFocus();+ fireEvent.keyDown(next, { key: 'ArrowUp' });expect(active).toHaveFocus();fireEvent.keyDown(window, { key: 'Escape' });