Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion e2e/accessibility.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
16 changes: 8 additions & 8 deletions e2e/i18n.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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');
});
});
20 changes: 20 additions & 0 deletions e2e/storage/connections-management.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions e2e/storage/context-menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions messages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/DateTimePicker.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
100 changes: 58 additions & 42 deletions src/lib/components/layout/header/LanguageSwitcher.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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();
}
</script>

<div
class={showLabel ? '' : 'tooltip tooltip-bottom z-150 before:z-200'}
data-tip={showLabel ? undefined : m.language_label()}
>
<button
class={`
btn btn-ghost btn-sm
${showLabel ? 'gap-2' : 'btn-square'}
`}
popovertarget="lang-switcher"
style="anchor-name:--lang-switcher"
aria-label={showLabel
? `${m.language_label()}: ${currentLocaleMeta.label()}`
: m.language_label()}
>
<IconLanguage class="h-5 w-5" aria-hidden="true" />
{#if showLabel}
<span class="text-sm font-medium">{currentLocaleMeta.label()}</span>
{/if}
</button>
</div>
<ul
class="
menu dropdown dropdown-end border-base-300 bg-base-100 w-40 rounded-lg
border p-1 shadow-lg
"
popover
id="lang-switcher"
style="position-anchor:--lang-switcher"
>
{#each availableLocales as locale (locale.code)}
{@const isActive = currentLocale === locale.code}
<li>
<Dropdown bind:open align="end" class="w-40 p-1" onopen={focusCurrent}>
{#snippet trigger(dropdown)}
<div
class={showLabel ? '' : 'tooltip tooltip-bottom z-150 before:z-200'}
data-tip={showLabel ? undefined : m.language_label()}
>
<button
lang={locale.code}
aria-current={isActive ? 'true' : undefined}
onclick={() => handleLocaleChange(locale.code)}
{...dropdown}
type="button"
class={`
btn btn-ghost btn-sm
${showLabel ? 'gap-2' : 'btn-square'}
`}
aria-label={showLabel
? `${m.language_label()}: ${currentLocaleMeta.label()}`
: m.language_label()}
>
<span>{locale.label()}</span>
{#if isActive}
<IconCheck class="h-4 w-4" aria-hidden="true" />
<IconLanguage class="h-5 w-5" aria-hidden="true" />
{#if showLabel}
<span class="text-sm font-medium">{currentLocaleMeta.label()}</span>
{/if}
</button>
</li>
{/each}
</ul>
</div>
{/snippet}
<ul
class="menu w-full p-0"
role="menu"
tabindex="-1"
aria-label={m.language_label()}
onkeydown={(e) => handleMenuKeydown(e, e.currentTarget)}
>
{#each availableLocales as locale (locale.code)}
{@const isActive = currentLocale === locale.code}
<li role="none">
<button
type="button"
role="menuitemradio"
tabindex="-1"
lang={locale.code}
aria-checked={isActive}
onclick={() => handleLocaleChange(locale.code)}
>
<span>{locale.label()}</span>
{#if isActive}
<IconCheck class="h-4 w-4" aria-hidden="true" />
{/if}
</button>
</li>
{/each}
</ul>
</Dropdown>
22 changes: 22 additions & 0 deletions src/lib/components/layout/header/LanguageSwitcher.svelte.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
58 changes: 35 additions & 23 deletions src/lib/components/layout/header/UserMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -18,33 +19,44 @@
);
</script>

<div class="dropdown dropdown-end">
<button tabindex="0" class="btn btn-ghost btn-circle" aria-label={m.header_user_menu()}>
{#if user.image}
<img src={user.image} alt={user.name ?? ''} class="h-8 w-8 rounded-full object-cover" />
{:else}
<span
class="bg-primary/10 text-primary flex h-8 w-8 items-center justify-center rounded-full text-xs font-semibold"
aria-hidden="true"
>
{initials}
</span>
{/if}
</button>
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
<ul
tabindex="0"
class="dropdown-content menu bg-base-100 border-base-300 z-10 w-56 rounded-lg border p-1 shadow-lg"
>
<li class="menu-title">
<p class="text-base-content truncate text-sm font-semibold">{user.name}</p>
<p class="text-muted truncate text-xs font-normal">{user.email}</p>
</li>
<!-- A panel rather than a menu: it shows who is signed in, with one link to sign out. -->
<Dropdown
align="end"
popup="dialog"
label={m.header_user_menu()}
class="w-56 p-1"
onopen={(panel) => panel.querySelector<HTMLElement>('a')?.focus()}
>
{#snippet trigger(dropdown)}
<button
{...dropdown}
type="button"
class="btn btn-ghost btn-circle"
aria-label={m.header_user_menu()}
>
{#if user.image}
<img src={user.image} alt={user.name ?? ''} class="h-8 w-8 rounded-full object-cover" />
{:else}
<span
class="bg-primary/10 text-primary flex h-8 w-8 items-center justify-center rounded-full text-xs font-semibold"
aria-hidden="true"
>
{initials}
</span>
{/if}
</button>
{/snippet}
<!-- Outside the menu list: DaisyUI's pressed style for menu items would hide the name. -->
<div class="px-3 py-2">
<p class="text-base-content truncate text-sm font-semibold">{user.name}</p>
<p class="text-muted truncate text-xs">{user.email}</p>
</div>
<ul class="menu w-full p-0">
<li class="border-base-300 mt-1 border-t pt-1">
<a href={resolve('/auth/logout')} class="text-sm">
<IconLogout class="h-4 w-4" aria-hidden="true" />
{m.header_sign_out()}
</a>
</li>
</ul>
</div>
</Dropdown>
26 changes: 26 additions & 0 deletions src/lib/components/layout/header/UserMenu.svelte.spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
2 changes: 1 addition & 1 deletion src/lib/components/storage/BucketSelect.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import * as m from '$lib/paraglide/messages.js';
import { supportsAnchorPositioning, trackPopover } from '$lib/components/popover-position.js';
import { supportsAnchorPositioning, trackPopover } from '$lib/components/ui/popover-position.js';
import type { SearchSession, StorageSearchState } from '$lib/storage/search.svelte.js';
import IconArrowDropDown from 'virtual:icons/material-symbols/arrow-drop-down';
import IconArrowDropUp from 'virtual:icons/material-symbols/arrow-drop-up';
Expand Down
Loading