diff --git a/e2e/accessibility.spec.ts b/e2e/accessibility.spec.ts index b338009f..336e1a5c 100644 --- a/e2e/accessibility.spec.ts +++ b/e2e/accessibility.spec.ts @@ -56,7 +56,14 @@ for (const theme of THEMES) { await page.goto('/trino'); await waitForHydration(page); await page.getByRole('button', { name: 'Select run mode' }).click(); - await expect(page.getByRole('menu', { name: 'Select run mode' })).toBeVisible(); + const menu = page.getByRole('menu', { name: 'Select run mode' }); + await expect(menu).toBeVisible(); + // The dropdown fades in; mid-fade its text is blended with the background. + await menu.evaluate((el) => + Promise.all( + (el.closest('[popover]')?.getAnimations() ?? []).map((animation) => animation.finished) + ) + ); await expectNoViolations(page); }); diff --git a/e2e/i18n.spec.ts b/e2e/i18n.spec.ts index 8fdda957..04ff79d8 100644 --- a/e2e/i18n.spec.ts +++ b/e2e/i18n.spec.ts @@ -58,10 +58,10 @@ test.describe('Internationalisation', () => { await waitForHydration(page); await page.getByRole('button', { name: 'Language' }).click(); - const englishOption = page.locator('#lang-switcher button[lang="en"]'); - const deutschOption = page.locator('#lang-switcher button[lang="de"]'); - await expect(englishOption).toHaveAttribute('aria-current', 'true'); - await expect(deutschOption).not.toHaveAttribute('aria-current', 'true'); + const englishOption = page.getByRole('menuitemradio', { name: 'English' }); + const deutschOption = page.getByRole('menuitemradio', { name: 'Deutsch' }); + await expect(englishOption).toHaveAttribute('aria-checked', 'true'); + await expect(deutschOption).not.toHaveAttribute('aria-checked', 'true'); // setLocale triggers a page reload when changing locale. await deutschOption.click(); @@ -137,14 +137,14 @@ test.describe('Internationalisation', () => { await languageButton.click(); // Both language options visible with correct lang attributes - const englishOption = page.locator('#lang-switcher button[lang="en"]'); - const deutschOption = page.locator('#lang-switcher button[lang="de"]'); + const englishOption = page.getByRole('menuitemradio', { name: 'English' }); + const deutschOption = page.getByRole('menuitemradio', { name: 'Deutsch' }); await expect(englishOption).toBeVisible(); await expect(deutschOption).toBeVisible(); await expect(englishOption).toHaveAttribute('lang', 'en'); await expect(deutschOption).toHaveAttribute('lang', 'de'); - await expect(englishOption).toHaveAttribute('aria-current', 'true'); - await expect(deutschOption).not.toHaveAttribute('aria-current', 'true'); + await expect(englishOption).toHaveAttribute('aria-checked', 'true'); + await expect(deutschOption).not.toHaveAttribute('aria-checked', 'true'); }); }); diff --git a/e2e/storage/connections-management.spec.ts b/e2e/storage/connections-management.spec.ts index e05a9686..f7ce3631 100644 --- a/e2e/storage/connections-management.spec.ts +++ b/e2e/storage/connections-management.spec.ts @@ -196,6 +196,26 @@ test.describe('Storage — Connections management', () => { await expect(dataRows).toHaveCount(initialItems - 1); }); + test('connection menu opens next to its button from the keyboard', async ({ page }) => { + const credentials = requireGarageCredentials(); + await connectToStorage(page, credentials); + await page.goto('/settings/connections'); + await waitForHydration(page); + + const button = page.getByRole('button', { name: /Options for/i }).first(); + await button.focus(); + await button.press('Enter'); + + const menu = page.getByRole('menu', { name: /Options for/i }); + await expect(menu.getByRole('menuitem').first()).toBeFocused(); + // Right below the button and aligned to its right edge, not in the top-left corner. + const buttonBox = (await button.boundingBox())!; + const menuBox = (await menu.boundingBox())!; + expect(menuBox.y).toBeGreaterThanOrEqual(buttonBox.y + buttonBox.height); + expect(menuBox.y - (buttonBox.y + buttonBox.height)).toBeLessThan(24); + expect(Math.abs(menuBox.x + menuBox.width - (buttonBox.x + buttonBox.width))).toBeLessThan(24); + }); + test('sidebar on the edit page deletes a connection', async ({ page }) => { const credentials = requireGarageCredentials(); await connectToStorage(page, credentials); diff --git a/e2e/storage/context-menu.spec.ts b/e2e/storage/context-menu.spec.ts index 979e05d5..b6b7c250 100644 --- a/e2e/storage/context-menu.spec.ts +++ b/e2e/storage/context-menu.spec.ts @@ -99,7 +99,7 @@ test.describe('Storage S3 — Context Menu', () => { } }); - test('unpins a pinned location from its sidebar menu', async ({ page }, testInfo) => { + test('unpins a pinned location with its sidebar button', async ({ page }, testInfo) => { const credentials = requireGarageCredentials(); const client = createS3Client(credentials); const prefix = uniquePrefix(testInfo, 'ctx-unpin'); @@ -119,11 +119,12 @@ test.describe('Storage S3 — Context Menu', () => { const sidebar = page.getByRole('navigation', { name: 'Buckets' }); await expect(sidebar.getByText('Pinned Access')).toBeVisible(); - await sidebar.getByRole('button', { name: 'More options' }).click({ force: true }); - const menu = page.getByRole('menu', { name: 'Actions' }); - await menu.getByRole('menuitem', { name: 'Unpin' }).click(); + // The unpin button shows on hover and on keyboard focus. + const unpin = sidebar.getByRole('button', { name: `Unpin ${credentials.bucket}` }); + await unpin.focus(); + await expect(unpin).toBeVisible(); + await unpin.press('Enter'); - await expect(menu).toHaveCount(0); await expect(sidebar.getByText('Pinned Access')).toHaveCount(0); } finally { await deleteKnownKeys(client, credentials.bucket, cleanupKeys); diff --git a/messages/de.json b/messages/de.json index 33059d9f..6988c941 100644 --- a/messages/de.json +++ b/messages/de.json @@ -323,6 +323,7 @@ "storage_action_pin": "Ort anheften", "storage_action_details": "Details", "storage_action_unpin": "Loslösen", + "storage_unpin_location": "{name} loslösen", "storage_action_copy_filename": "Dateiname kopieren", "storage_action_copy_filename_success": "Dateiname in die Zwischenablage kopiert.", "storage_action_copy_filename_error": "Dateiname konnte nicht in die Zwischenablage kopiert werden.", diff --git a/messages/en.json b/messages/en.json index 647dbc5e..209154e8 100644 --- a/messages/en.json +++ b/messages/en.json @@ -323,6 +323,7 @@ "storage_action_pin": "Pin this location", "storage_action_details": "Details", "storage_action_unpin": "Unpin", + "storage_unpin_location": "Unpin {name}", "storage_action_copy_filename": "Copy filename", "storage_action_copy_filename_success": "Filename copied to clipboard.", "storage_action_copy_filename_error": "Could not copy filename to clipboard.", diff --git a/src/lib/components/DateTimePicker.svelte b/src/lib/components/DateTimePicker.svelte index a3b47531..e6efcbe6 100644 --- a/src/lib/components/DateTimePicker.svelte +++ b/src/lib/components/DateTimePicker.svelte @@ -9,7 +9,7 @@ positionPopoverRelativeToTrigger, supportsAnchorPositioning, trackPopover - } from '$lib/components/popover-position.js'; + } from '$lib/components/ui/popover-position.js'; import IconCalendar from 'virtual:icons/material-symbols/calendar-today'; import IconChevronLeft from 'virtual:icons/material-symbols/chevron-left'; import IconChevronRight from 'virtual:icons/material-symbols/chevron-right'; diff --git a/src/lib/components/layout/header/LanguageSwitcher.svelte b/src/lib/components/layout/header/LanguageSwitcher.svelte index 642881bb..a035d76c 100644 --- a/src/lib/components/layout/header/LanguageSwitcher.svelte +++ b/src/lib/components/layout/header/LanguageSwitcher.svelte @@ -3,6 +3,8 @@ import { getLocale, setLocale, locales } from '$lib/paraglide/runtime.js'; import IconLanguage from 'virtual:icons/material-symbols/language'; import IconCheck from 'virtual:icons/material-symbols/check'; + import Dropdown from '$lib/components/ui/Dropdown.svelte'; + import { handleMenuKeydown, menuItems } from '$lib/components/ui/menu-keyboard.js'; type LocaleMeta = { code: (typeof locales)[number]; @@ -21,54 +23,68 @@ availableLocales.find((locale) => locale.code === currentLocale) ?? availableLocales[0] ); + let open = $state(false); + function handleLocaleChange(locale: (typeof locales)[number]) { + open = false; void setLocale(locale); } + + /** Focuses the current language when the menu opens. */ + function focusCurrent(panel: HTMLElement) { + const items = menuItems(panel); + (items.find((item) => item.getAttribute('aria-checked') === 'true') ?? items[0])?.focus(); + } -
- -
- + + {/snippet} + + diff --git a/src/lib/components/layout/header/LanguageSwitcher.svelte.spec.ts b/src/lib/components/layout/header/LanguageSwitcher.svelte.spec.ts new file mode 100644 index 00000000..f44668c8 --- /dev/null +++ b/src/lib/components/layout/header/LanguageSwitcher.svelte.spec.ts @@ -0,0 +1,22 @@ +import { page, userEvent } from 'vitest/browser'; +import { describe, expect, it } from 'vitest'; +import { render } from 'vitest-browser-svelte'; +import LanguageSwitcher from './LanguageSwitcher.svelte'; + +describe('LanguageSwitcher', () => { + it('opens with the focus on the current language, which is checked', async () => { + render(LanguageSwitcher); + + await page.getByRole('button', { name: 'Language' }).click(); + + const english = page.getByRole('menuitemradio', { name: 'English' }); + await expect.element(english).toHaveFocus(); + await expect.element(english).toHaveAttribute('aria-checked', 'true'); + await expect + .element(page.getByRole('menuitemradio', { name: 'Deutsch' })) + .toHaveAttribute('aria-checked', 'false'); + + await userEvent.keyboard('{ArrowDown}'); + await expect.element(page.getByRole('menuitemradio', { name: 'Deutsch' })).toHaveFocus(); + }); +}); diff --git a/src/lib/components/layout/header/UserMenu.svelte b/src/lib/components/layout/header/UserMenu.svelte index c47434ef..c0d8d256 100644 --- a/src/lib/components/layout/header/UserMenu.svelte +++ b/src/lib/components/layout/header/UserMenu.svelte @@ -2,6 +2,7 @@ import { resolve } from '$app/paths'; import * as m from '$lib/paraglide/messages.js'; import IconLogout from 'virtual:icons/material-symbols/logout'; + import Dropdown from '$lib/components/ui/Dropdown.svelte'; import type { User } from '$lib/types/auth.js'; let { user }: { user: User } = $props(); @@ -18,28 +19,39 @@ ); - + diff --git a/src/lib/components/layout/header/UserMenu.svelte.spec.ts b/src/lib/components/layout/header/UserMenu.svelte.spec.ts new file mode 100644 index 00000000..3f248b0b --- /dev/null +++ b/src/lib/components/layout/header/UserMenu.svelte.spec.ts @@ -0,0 +1,26 @@ +import { page, userEvent } from 'vitest/browser'; +import { describe, expect, it } from 'vitest'; +import { render } from 'vitest-browser-svelte'; +import type { User } from '$lib/types/auth.js'; +import UserMenu from './UserMenu.svelte'; + +const user = { id: 'u1', name: 'Ada Lovelace', email: 'ada@example.com', image: null } as User; + +describe('UserMenu', () => { + it('opens above the page with the focus on the sign out link', async () => { + render(UserMenu, { user }); + + await page.getByRole('button', { name: 'User menu' }).click(); + + const panel = page.getByRole('dialog', { name: 'User menu' }); + await expect.element(panel).toBeVisible(); + // A popover in the top layer, so no z-index on the page can cover it. + expect(panel.element().matches(':popover-open')).toBe(true); + await expect.element(panel.getByText('ada@example.com')).toBeVisible(); + await expect.element(page.getByRole('link', { name: 'Sign out' })).toHaveFocus(); + + await userEvent.keyboard('{Escape}'); + await expect.element(panel).not.toBeInTheDocument(); + await expect.element(page.getByRole('button', { name: 'User menu' })).toHaveFocus(); + }); +}); diff --git a/src/lib/components/storage/BucketSelect.svelte b/src/lib/components/storage/BucketSelect.svelte index 75ca4bab..ab684d9a 100644 --- a/src/lib/components/storage/BucketSelect.svelte +++ b/src/lib/components/storage/BucketSelect.svelte @@ -1,6 +1,6 @@ - e.key === 'Escape' && (dropdownOpen = false)} /> - {#if visibleOps.length > 0 || storage.downloadHistory.length > 0 || storage.downloadHistoryLoading} - {#if dropdownOpen} -
(dropdownOpen = false)} - oncontextmenu={(e) => { - e.preventDefault(); - dropdownOpen = false; - }} - role="presentation" - aria-hidden="true" - >
- {/if} -
- -
- -
- - - {#if dropdownOpen} -
e.preventDefault()} - aria-label={m.storage_operations_label()} - class="rounded-box border-base-300 bg-base-100 absolute right-0 z-60 mt-2 flex max-h-[calc(100dvh-6rem)] w-[min(24rem,calc(100vw-1rem))] origin-top-right flex-col overflow-hidden border shadow-xl" - > - - {#if activeOps.length > 0} -
-

- {m.storage_operations_active()} -

-
    - {#each activeOps as op (op.id)} - {@const TypeIcon = typeIconMap[op.type]} -
  • - -
    -
    toggleExpand(op.id)} - onkeydown={(e) => { - if (e.key === 'Enter' || e.key === ' ') { - e.preventDefault(); - toggleExpand(op.id); - } - }} - aria-expanded={expandedOps[op.id]} + +
    + {/snippet} + +
    + + {#if activeOps.length > 0} +
    +

    + {m.storage_operations_active()} +

    +
      + {#each activeOps as op (op.id)} + {@const TypeIcon = typeIconMap[op.type]} +
    • + +
      +
      toggleExpand(op.id)} + onkeydown={(e) => { + if (e.key === 'Enter' || e.key === ' ') { + e.preventDefault(); + toggleExpand(op.id); + } + }} + aria-expanded={expandedOps[op.id]} + > + + - - - {op.label} - + + - - {#if op.totalBytes > 0} - - {speedEtaLabel(op)} - - {/if} -
      + + + {op.label} + - -
      - -
      + + {#if op.totalBytes > 0} + + {speedEtaLabel(op)} + + {/if}
      - - {#if expandedOps[op.id]} -
      - - {#if op.currentFileName} -
      - {op.currentFileName} -
      - {/if} - - - {#if op.totalBytes > 0 || op.itemCount > 1} -
      0 - ? Math.min(displayBytes(op), op.totalBytes) - : op.completedCount} - aria-valuemin={0} - aria-valuemax={op.totalBytes > 0 ? op.totalBytes : op.itemCount} - aria-label={op.label} - > -
      - - {progressLabel(op)} - - - {#if op.totalBytes > 0} - {percent(op)}% - {:else} - {op.completedCount}/{op.itemCount} - {/if} - -
      -
      -
      -
      -
      - {/if} - - - {#if op.sourceNames && op.sourceNames.length > 0} -
      - {#each op.sourceNames as name, i (i)} -
      - {#if name === op.currentFileName} - - {:else if i < op.completedCount} - - {:else} - - {/if} - {name} -
      - {/each} -
      - {/if} + +
      + +
      +
      - -
      - {formatElapsed(op.startedAt, op.completedAt)} -
      -
    - {:else} - + + {#if expandedOps[op.id]} +
    + {#if op.currentFileName} -
    +
    {op.currentFileName}
    {/if} - {/if} -
  • - {/each} -
-
- {/if} - - - {#if hasAnyHistory} -
-
-

- {m.storage_operations_history()} -

- -
- {#if hasHistory} -
    - {#each historyOps as op (op.id)} - {@const TypeIcon = typeIconMap[op.type]} -
  • -
    - - - - - - {op.label} - -
    - - {statusLabel(op)} - - - {formatElapsed(op.startedAt, op.completedAt)} - -
    -
    - - {#if op.status === 'error' && op.errorMessage} + + {#if op.totalBytes > 0 || op.itemCount > 1}
    0 + ? Math.min(displayBytes(op), op.totalBytes) + : op.completedCount} + aria-valuemin={0} + aria-valuemax={op.totalBytes > 0 ? op.totalBytes : op.itemCount} + aria-label={op.label} > - {op.errorMessage} -
    - {:else if op.status === 'interrupted'} -
    - {m.storage_operations_interrupted_tooltip()} -
    - {:else if op.status === 'unknown'} -
    - {m.storage_operations_unknown_tooltip()} -
    - {/if} - - - {#if (op.status === 'interrupted' || op.status === 'unknown' || op.status === 'error') && op.totalBytes > 0} -
    -
    +
    + + {progressLabel(op)} + + + {#if op.totalBytes > 0} + {percent(op)}% + {:else} + {op.completedCount}/{op.itemCount} + {/if} + +
    +
    - - {formatBytes(op.completedBytes)} / {formatBytes(op.totalBytes)} -
    {/if} -
  • - {/each} -
- {/if} -
- {:else if activeOps.length === 0} -
-
+ {:else} + + {#if op.currentFileName} +
+ {op.currentFileName} +
+ {/if} + {/if} + + {/each} + +
+ {/if} + + + {#if hasAnyHistory} +
+
+

+ {m.storage_operations_history()} +

+
- {/if} - storage.redownloadHistory(id, keys)} - /> -
- {/if} -
+ {#if hasHistory} + + {/if} + + {:else if activeOps.length === 0} +
+
+ {/if} + storage.redownloadHistory(id, keys)} + /> + + {/if} diff --git a/src/lib/components/storage/explorer/StorageBreadcrumb.svelte b/src/lib/components/storage/explorer/StorageBreadcrumb.svelte index c148017d..c2eee773 100644 --- a/src/lib/components/storage/explorer/StorageBreadcrumb.svelte +++ b/src/lib/components/storage/explorer/StorageBreadcrumb.svelte @@ -22,7 +22,10 @@ import { storageTransferEnabled } from '$lib/client/feature-flags.js'; import { parseStorageDrop, canStorageDrop } from '$lib/storage/drag-handlers.js'; import OperationsButton from './OperationsButton.svelte'; - import ContextMenu, { type ContextMenuAction } from '$lib/components/ui/ContextMenu.svelte'; + import ContextMenu from '$lib/components/ui/ContextMenu.svelte'; + import MenuItems, { type MenuAction } from '$lib/components/ui/MenuItems.svelte'; + import Dropdown from '$lib/components/ui/Dropdown.svelte'; + import { menuItems } from '$lib/components/ui/menu-keyboard.js'; import TooltipTrigger from '$lib/components/ui/TooltipTrigger.svelte'; const storage = getStorageState(); @@ -83,8 +86,8 @@ objectNameError(createName, { prefix: storage.prefix, folder: createType === 'folder' }) ); - function openCreate() { - createOpen = true; + /** Starts over at the type choice; runs on the trigger's click, before the popover opens. */ + function resetCreate() { createStep = 'choose'; createType = 'file'; createName = ''; @@ -95,6 +98,11 @@ createOpen = false; } + const createTypeActions = $derived([ + { key: 'file', icon: IconDescriptionOutline, label: m.storage_create_file() }, + { key: 'folder', icon: IconFolderOutline, label: m.storage_create_folder() } + ]); + function selectCreateType(type: 'file' | 'folder') { createType = type; createStep = 'name'; @@ -140,7 +148,7 @@ breadcrumbCtx = null; } - const breadcrumbMenuActions = $derived.by(() => { + const breadcrumbMenuActions = $derived.by(() => { const ctx = breadcrumbCtx; if (!ctx) return []; const isPinned = storage.bookmarks.isPinned(ctx.bucket, ctx.prefix); @@ -562,103 +570,69 @@ - {/if} - + {#if !storage.archive.isInArchive} diff --git a/src/lib/components/storage/explorer/TabBar.svelte b/src/lib/components/storage/explorer/TabBar.svelte index b91b84a9..ad14c7b6 100644 --- a/src/lib/components/storage/explorer/TabBar.svelte +++ b/src/lib/components/storage/explorer/TabBar.svelte @@ -8,7 +8,8 @@ import { getStorageState } from '$lib/storage/context.js'; import { storageTransferEnabled } from '$lib/client/feature-flags.js'; import { parseStorageDrop } from '$lib/storage/drag-handlers.js'; - import ContextMenu, { type ContextMenuAction } from '$lib/components/ui/ContextMenu.svelte'; + import ContextMenu from '$lib/components/ui/ContextMenu.svelte'; + import type { MenuAction } from '$lib/components/ui/MenuItems.svelte'; import GenericTabBar, { type ExternalTabDrag } from '$lib/components/ui/TabBar.svelte'; interface Props { @@ -76,7 +77,7 @@ ctxMenu = null; } - const tabMenuActions = $derived.by(() => { + const tabMenuActions = $derived.by(() => { if (!ctxMenu) return []; return [ { diff --git a/src/lib/components/storage/explorer/__tests__/StorageBreadcrumb.svelte.spec.ts b/src/lib/components/storage/explorer/__tests__/StorageBreadcrumb.svelte.spec.ts index b7677e7f..def1525d 100644 --- a/src/lib/components/storage/explorer/__tests__/StorageBreadcrumb.svelte.spec.ts +++ b/src/lib/components/storage/explorer/__tests__/StorageBreadcrumb.svelte.spec.ts @@ -200,6 +200,22 @@ describe('StorageBreadcrumb', () => { }); describe('create menu', () => { + it('starts over at the type choice when opened again', async () => { + render(StorageBreadcrumbWrapper, { state: createState() }); + const create = page.getByRole('button', { name: 'Create', exact: true }); + + await create.click(); + await expect.element(page.getByRole('menuitem', { name: /text file/i })).toHaveFocus(); + await page.getByRole('menuitem', { name: /text file/i }).click(); + await expect.element(page.getByLabelText('Name')).toHaveFocus(); + await userEvent.keyboard('{Escape}'); + await expect.element(create).toHaveFocus(); + + await create.click(); + await expect.element(page.getByRole('menuitem', { name: /text file/i })).toHaveFocus(); + expect(page.getByLabelText('Name').query()).toBeNull(); + }); + it('should ignore Enter while a create is in flight', async () => { const state = createState(); let resolveCreate: (created: boolean) => void = () => {}; diff --git a/src/lib/components/storage/modals/details/Treemap.svelte b/src/lib/components/storage/modals/details/Treemap.svelte index 5e71a00b..e28feb68 100644 --- a/src/lib/components/storage/modals/details/Treemap.svelte +++ b/src/lib/components/storage/modals/details/Treemap.svelte @@ -4,7 +4,8 @@ import * as m from '$lib/paraglide/messages.js'; import IconContentCopy from 'virtual:icons/material-symbols/content-copy'; import IconFolderOpen from 'virtual:icons/material-symbols/folder-open'; - import ContextMenu, { type ContextMenuAction } from '$lib/components/ui/ContextMenu.svelte'; + import ContextMenu from '$lib/components/ui/ContextMenu.svelte'; + import type { MenuAction } from '$lib/components/ui/MenuItems.svelte'; interface Props { data: TreemapNode; @@ -177,7 +178,7 @@ ctxMenu = null; } - const ctxActions = $derived.by(() => { + const ctxActions = $derived.by(() => { const target = ctxMenu?.target; if (!target) return []; return [ diff --git a/src/lib/components/storage/sidebar/BucketList.svelte b/src/lib/components/storage/sidebar/BucketList.svelte index 9bd90d9e..8b73deb0 100644 --- a/src/lib/components/storage/sidebar/BucketList.svelte +++ b/src/lib/components/storage/sidebar/BucketList.svelte @@ -1,8 +1,6 @@ - -