Compare commits
4 Commits
feat/issue
...
feat/issue
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3de3b2131f | ||
|
|
94b8117c17 | ||
|
|
a3343f898f | ||
|
|
533196dabb |
@@ -32,6 +32,9 @@
|
|||||||
"layout_menu_close": "Menü schließen",
|
"layout_menu_close": "Menü schließen",
|
||||||
"theme_toggle_to_light": "Zu hellem Design wechseln",
|
"theme_toggle_to_light": "Zu hellem Design wechseln",
|
||||||
"theme_toggle_to_dark": "Zu dunklem Design wechseln",
|
"theme_toggle_to_dark": "Zu dunklem Design wechseln",
|
||||||
|
"theme_toggle_label": "Farbschema",
|
||||||
|
"theme_segment_light": "Hell",
|
||||||
|
"theme_segment_dark": "Dunkel",
|
||||||
"btn_save": "Speichern",
|
"btn_save": "Speichern",
|
||||||
"btn_cancel": "Abbrechen",
|
"btn_cancel": "Abbrechen",
|
||||||
"btn_confirm": "Bestätigen",
|
"btn_confirm": "Bestätigen",
|
||||||
@@ -193,8 +196,6 @@
|
|||||||
"person_no_docs": "Diese Person ist noch nicht als Absender verknüpft.",
|
"person_no_docs": "Diese Person ist noch nicht als Absender verknüpft.",
|
||||||
"person_received_docs_heading": "Empfangene Dokumente",
|
"person_received_docs_heading": "Empfangene Dokumente",
|
||||||
"person_no_received_docs": "Diese Person ist noch nicht als Empfänger verknüpft.",
|
"person_no_received_docs": "Diese Person ist noch nicht als Empfänger verknüpft.",
|
||||||
"person_meta_doc_count": "{count} Dokumente",
|
|
||||||
"person_meta_rel_count": "{count} Beziehungen",
|
|
||||||
"person_role_sender": "Gesendet",
|
"person_role_sender": "Gesendet",
|
||||||
"person_role_receiver": "Empfangen",
|
"person_role_receiver": "Empfangen",
|
||||||
"person_co_correspondents_heading": "Häufige Korrespondenten",
|
"person_co_correspondents_heading": "Häufige Korrespondenten",
|
||||||
|
|||||||
@@ -32,6 +32,9 @@
|
|||||||
"layout_menu_close": "Close menu",
|
"layout_menu_close": "Close menu",
|
||||||
"theme_toggle_to_light": "Switch to light mode",
|
"theme_toggle_to_light": "Switch to light mode",
|
||||||
"theme_toggle_to_dark": "Switch to dark mode",
|
"theme_toggle_to_dark": "Switch to dark mode",
|
||||||
|
"theme_toggle_label": "Color scheme",
|
||||||
|
"theme_segment_light": "Light",
|
||||||
|
"theme_segment_dark": "Dark",
|
||||||
"btn_save": "Save",
|
"btn_save": "Save",
|
||||||
"btn_cancel": "Cancel",
|
"btn_cancel": "Cancel",
|
||||||
"btn_confirm": "Confirm",
|
"btn_confirm": "Confirm",
|
||||||
@@ -193,8 +196,6 @@
|
|||||||
"person_no_docs": "This person has not yet been linked as a sender.",
|
"person_no_docs": "This person has not yet been linked as a sender.",
|
||||||
"person_received_docs_heading": "Received documents",
|
"person_received_docs_heading": "Received documents",
|
||||||
"person_no_received_docs": "This person has not yet been linked as a receiver.",
|
"person_no_received_docs": "This person has not yet been linked as a receiver.",
|
||||||
"person_meta_doc_count": "{count} documents",
|
|
||||||
"person_meta_rel_count": "{count} relationships",
|
|
||||||
"person_role_sender": "Sent",
|
"person_role_sender": "Sent",
|
||||||
"person_role_receiver": "Received",
|
"person_role_receiver": "Received",
|
||||||
"person_co_correspondents_heading": "Frequent correspondents",
|
"person_co_correspondents_heading": "Frequent correspondents",
|
||||||
|
|||||||
@@ -32,6 +32,9 @@
|
|||||||
"layout_menu_close": "Cerrar menú",
|
"layout_menu_close": "Cerrar menú",
|
||||||
"theme_toggle_to_light": "Cambiar a modo claro",
|
"theme_toggle_to_light": "Cambiar a modo claro",
|
||||||
"theme_toggle_to_dark": "Cambiar a modo oscuro",
|
"theme_toggle_to_dark": "Cambiar a modo oscuro",
|
||||||
|
"theme_toggle_label": "Esquema de color",
|
||||||
|
"theme_segment_light": "Claro",
|
||||||
|
"theme_segment_dark": "Oscuro",
|
||||||
"btn_save": "Guardar",
|
"btn_save": "Guardar",
|
||||||
"btn_cancel": "Cancelar",
|
"btn_cancel": "Cancelar",
|
||||||
"btn_confirm": "Confirmar",
|
"btn_confirm": "Confirmar",
|
||||||
@@ -193,8 +196,6 @@
|
|||||||
"person_no_docs": "Esta persona aún no está vinculada como remitente.",
|
"person_no_docs": "Esta persona aún no está vinculada como remitente.",
|
||||||
"person_received_docs_heading": "Documentos recibidos",
|
"person_received_docs_heading": "Documentos recibidos",
|
||||||
"person_no_received_docs": "Esta persona aún no está vinculada como receptor.",
|
"person_no_received_docs": "Esta persona aún no está vinculada como receptor.",
|
||||||
"person_meta_doc_count": "{count} documentos",
|
|
||||||
"person_meta_rel_count": "{count} relaciones",
|
|
||||||
"person_role_sender": "Enviado",
|
"person_role_sender": "Enviado",
|
||||||
"person_role_receiver": "Recibido",
|
"person_role_receiver": "Recibido",
|
||||||
"person_co_correspondents_heading": "Corresponsales frecuentes",
|
"person_co_correspondents_heading": "Corresponsales frecuentes",
|
||||||
|
|||||||
@@ -54,10 +54,11 @@ function setReview(next: boolean) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// §6 tokens: Montserrat 12px/700 tracking-[.08em] UPPERCASE; 44px touch target
|
||||||
const chipBase =
|
const chipBase =
|
||||||
'inline-flex min-h-[44px] min-w-[44px] items-center gap-1.5 rounded-sm border px-4 py-2 font-sans text-sm font-semibold transition-colors focus-visible:ring-2 focus-visible:ring-brand-navy focus-visible:ring-offset-2 focus-visible:outline-none';
|
'inline-flex min-h-[44px] min-w-[44px] items-center gap-1.5 rounded-sm border px-4 py-[9px] font-sans text-xs font-bold tracking-[.08em] uppercase transition-colors focus-visible:ring-2 focus-visible:ring-focus-ring focus-visible:ring-offset-2 focus-visible:outline-none';
|
||||||
const chipActive = 'border-brand-navy bg-brand-navy text-white';
|
const chipActive = 'border-primary bg-primary text-primary-fg';
|
||||||
const chipInactive = 'border-line bg-surface text-ink hover:bg-muted';
|
const chipInactive = 'border-line bg-surface text-ink-2 hover:bg-surface-2';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center">
|
<div class="flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center">
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
<script lang="ts">
|
|
||||||
let {
|
|
||||||
items,
|
|
||||||
iconSrc
|
|
||||||
}: {
|
|
||||||
items: string[];
|
|
||||||
iconSrc?: string;
|
|
||||||
} = $props();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{#if items.length > 0}
|
|
||||||
<div
|
|
||||||
data-testid="meta-line"
|
|
||||||
style="display:flex; align-items:center; flex-wrap:wrap; gap:8px; font-family:var(--font-sans); font-size:12px; color:var(--c-ink-2);"
|
|
||||||
>
|
|
||||||
{#if iconSrc}
|
|
||||||
<img src={iconSrc} alt="" style="width:14px; height:14px; opacity:0.5; flex-shrink:0;" />
|
|
||||||
{/if}
|
|
||||||
{#each items as item, i (i)}
|
|
||||||
{#if i > 0}
|
|
||||||
<span data-testid="meta-sep" aria-hidden="true">·</span>
|
|
||||||
{/if}
|
|
||||||
<span data-testid="meta-item">{item}</span>
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
import { afterEach, describe, expect, it } from 'vitest';
|
|
||||||
import { cleanup, render } from 'vitest-browser-svelte';
|
|
||||||
import MetaLine from './MetaLine.svelte';
|
|
||||||
|
|
||||||
afterEach(() => cleanup());
|
|
||||||
|
|
||||||
describe('MetaLine', () => {
|
|
||||||
it('renders N item spans when given N items', async () => {
|
|
||||||
render(MetaLine, { items: ['14. März 1923', '14 Dokumente', '4 Personen'] });
|
|
||||||
const spans = document.querySelectorAll('[data-testid="meta-item"]');
|
|
||||||
expect(spans).toHaveLength(3);
|
|
||||||
expect(spans[0].textContent).toBe('14. März 1923');
|
|
||||||
expect(spans[1].textContent).toBe('14 Dokumente');
|
|
||||||
expect(spans[2].textContent).toBe('4 Personen');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders separator spans between items', async () => {
|
|
||||||
render(MetaLine, { items: ['A', 'B', 'C'] });
|
|
||||||
const seps = document.querySelectorAll('[data-testid="meta-sep"]');
|
|
||||||
// N items → N-1 separators
|
|
||||||
expect(seps).toHaveLength(2);
|
|
||||||
expect(seps[0].textContent).toBe('·');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders nothing when items is empty', async () => {
|
|
||||||
const { container } = render(MetaLine, { items: [] });
|
|
||||||
// No element children — Svelte may leave an empty comment node but no DOM elements
|
|
||||||
expect(container.querySelectorAll('[data-testid]')).toHaveLength(0);
|
|
||||||
expect(container.querySelectorAll('div, span, img')).toHaveLength(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('renders nothing when items has one element (no separator)', async () => {
|
|
||||||
render(MetaLine, { items: ['Nur eines'] });
|
|
||||||
const seps = document.querySelectorAll('[data-testid="meta-sep"]');
|
|
||||||
expect(seps).toHaveLength(0);
|
|
||||||
const spans = document.querySelectorAll('[data-testid="meta-item"]');
|
|
||||||
expect(spans).toHaveLength(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('shows the leading img when iconSrc is supplied', async () => {
|
|
||||||
render(MetaLine, {
|
|
||||||
items: ['Datum'],
|
|
||||||
iconSrc: '/degruyter-icons/Simple/Small-16px/SVG/Action/Calendar-Add-SM.svg'
|
|
||||||
});
|
|
||||||
const img = document.querySelector('img');
|
|
||||||
expect(img).not.toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does NOT render an img when iconSrc is omitted', async () => {
|
|
||||||
render(MetaLine, { items: ['Datum'] });
|
|
||||||
const img = document.querySelector('img');
|
|
||||||
expect(img).toBeNull();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('icon has width 14px, height 14px, opacity 0.5, and alt=""', async () => {
|
|
||||||
render(MetaLine, {
|
|
||||||
items: ['Datum'],
|
|
||||||
iconSrc: '/degruyter-icons/Simple/Small-16px/SVG/Action/Calendar-Add-SM.svg'
|
|
||||||
});
|
|
||||||
const img = document.querySelector('img') as HTMLImageElement;
|
|
||||||
expect(img.alt).toBe('');
|
|
||||||
// Inline style values (set directly on the element, not via getComputedStyle)
|
|
||||||
expect(img.style.width).toBe('14px');
|
|
||||||
expect(img.style.height).toBe('14px');
|
|
||||||
expect(img.style.opacity).toBe('0.5');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('applies font-size 12px to the wrapper', async () => {
|
|
||||||
render(MetaLine, { items: ['Test'] });
|
|
||||||
const wrapper = document.querySelector('[data-testid="meta-line"]') as HTMLElement;
|
|
||||||
expect(wrapper).not.toBeNull();
|
|
||||||
expect(wrapper.style.fontSize).toBe('12px');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
55
frontend/src/lib/shared/primitives/SegmentedControl.svelte
Normal file
55
frontend/src/lib/shared/primitives/SegmentedControl.svelte
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { radioGroupNav } from '$lib/shared/actions/radioGroupNav';
|
||||||
|
|
||||||
|
interface Option {
|
||||||
|
value: string;
|
||||||
|
label: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
options: Option[];
|
||||||
|
value: string;
|
||||||
|
onChange: (value: string) => void;
|
||||||
|
label?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
let { options, value, onChange, label = undefined }: Props = $props();
|
||||||
|
|
||||||
|
// Roving tabindex: the active segment gets tabindex=0; all others -1.
|
||||||
|
// If no segment is active yet, fall back to the first so keyboard nav
|
||||||
|
// can enter the control.
|
||||||
|
const rovingFocus = $derived(
|
||||||
|
options.some((o) => o.value === value) ? value : (options[0]?.value ?? '')
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
§6 Segmented Control — single-select, radiogroup + roving tabindex.
|
||||||
|
Callers supply pre-resolved Paraglide strings for all labels.
|
||||||
|
No {@html} is used on option labels (XSS-safe default escaping only).
|
||||||
|
-->
|
||||||
|
<div
|
||||||
|
role="radiogroup"
|
||||||
|
aria-label={label}
|
||||||
|
class="inline-flex flex-wrap rounded-sm border border-line md:flex-nowrap"
|
||||||
|
use:radioGroupNav={(v) => onChange(v)}
|
||||||
|
>
|
||||||
|
{#each options as option, i (option.value)}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
role="radio"
|
||||||
|
value={option.value}
|
||||||
|
aria-checked={option.value === value}
|
||||||
|
tabindex={option.value === rovingFocus ? 0 : -1}
|
||||||
|
onclick={() => onChange(option.value)}
|
||||||
|
class="min-h-[44px] cursor-pointer px-4 py-[9px] font-sans text-xs font-bold tracking-[.08em]
|
||||||
|
uppercase transition-colors
|
||||||
|
focus:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring focus-visible:ring-inset
|
||||||
|
{i > 0 ? 'border-l border-line' : ''}
|
||||||
|
{option.value === value
|
||||||
|
? 'bg-primary text-primary-fg'
|
||||||
|
: 'hover:bg-surface-2 bg-surface text-ink-2'}"
|
||||||
|
>{option.label}</button
|
||||||
|
>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,170 @@
|
|||||||
|
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||||
|
import { cleanup, render } from 'vitest-browser-svelte';
|
||||||
|
import { page, userEvent } from 'vitest/browser';
|
||||||
|
|
||||||
|
afterEach(cleanup);
|
||||||
|
|
||||||
|
const options = [
|
||||||
|
{ value: 'a', label: 'Option A' },
|
||||||
|
{ value: 'b', label: 'Option B' },
|
||||||
|
{ value: 'c', label: 'Option C' }
|
||||||
|
];
|
||||||
|
|
||||||
|
const { default: SegmentedControl } = await import('./SegmentedControl.svelte');
|
||||||
|
|
||||||
|
// ─── Structure & ARIA ─────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
describe('SegmentedControl — structure', () => {
|
||||||
|
it('renders a radiogroup wrapper', async () => {
|
||||||
|
render(SegmentedControl, { props: { options, value: 'a', onChange: vi.fn() } });
|
||||||
|
const group = document.querySelector('[role="radiogroup"]');
|
||||||
|
expect(group).not.toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders one radio per option with the correct label', async () => {
|
||||||
|
render(SegmentedControl, { props: { options, value: 'a', onChange: vi.fn() } });
|
||||||
|
await expect.element(page.getByRole('radio', { name: 'Option A' })).toBeVisible();
|
||||||
|
await expect.element(page.getByRole('radio', { name: 'Option B' })).toBeVisible();
|
||||||
|
await expect.element(page.getByRole('radio', { name: 'Option C' })).toBeVisible();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('active segment has aria-checked="true", inactive ones "false"', async () => {
|
||||||
|
render(SegmentedControl, { props: { options, value: 'b', onChange: vi.fn() } });
|
||||||
|
await expect
|
||||||
|
.element(page.getByRole('radio', { name: 'Option B' }))
|
||||||
|
.toHaveAttribute('aria-checked', 'true');
|
||||||
|
await expect
|
||||||
|
.element(page.getByRole('radio', { name: 'Option A' }))
|
||||||
|
.toHaveAttribute('aria-checked', 'false');
|
||||||
|
await expect
|
||||||
|
.element(page.getByRole('radio', { name: 'Option C' }))
|
||||||
|
.toHaveAttribute('aria-checked', 'false');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('active segment gets tabindex=0, inactive segments tabindex=-1', async () => {
|
||||||
|
render(SegmentedControl, { props: { options, value: 'a', onChange: vi.fn() } });
|
||||||
|
const radios = Array.from(document.querySelectorAll('[role="radio"]'));
|
||||||
|
expect(radios[0]?.getAttribute('tabindex')).toBe('0');
|
||||||
|
expect(radios[1]?.getAttribute('tabindex')).toBe('-1');
|
||||||
|
expect(radios[2]?.getAttribute('tabindex')).toBe('-1');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('applies §6 active token classes to the active segment', async () => {
|
||||||
|
render(SegmentedControl, { props: { options, value: 'a', onChange: vi.fn() } });
|
||||||
|
const activeRadio = page.getByRole('radio', { name: 'Option A' });
|
||||||
|
await expect.element(activeRadio).toHaveClass(/bg-primary/);
|
||||||
|
await expect.element(activeRadio).toHaveClass(/text-primary-fg/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('applies §6 inactive token classes to inactive segments', async () => {
|
||||||
|
render(SegmentedControl, { props: { options, value: 'a', onChange: vi.fn() } });
|
||||||
|
const inactiveRadio = page.getByRole('radio', { name: 'Option B' });
|
||||||
|
await expect.element(inactiveRadio).toHaveClass(/bg-surface/);
|
||||||
|
await expect.element(inactiveRadio).toHaveClass(/text-ink-2/);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('segment labels are rendered as plain text — no innerHTML injection', async () => {
|
||||||
|
const xssOptions = [{ value: 'x', label: '<img src=x onerror=alert(1)>' }];
|
||||||
|
render(SegmentedControl, { props: { options: xssOptions, value: 'x', onChange: vi.fn() } });
|
||||||
|
// If the label were injected via {@html}, an <img> element would appear
|
||||||
|
const imgs = document.querySelectorAll('img');
|
||||||
|
expect(imgs.length).toBe(0);
|
||||||
|
// The raw text string should appear literally
|
||||||
|
const radio = document.querySelector('[role="radio"]');
|
||||||
|
expect(radio?.textContent).toContain('<img');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('wrapper has border border-line rounded-sm tokens', async () => {
|
||||||
|
render(SegmentedControl, { props: { options, value: 'a', onChange: vi.fn() } });
|
||||||
|
const group = document.querySelector('[role="radiogroup"]');
|
||||||
|
expect(group?.className).toMatch(/border-line/);
|
||||||
|
expect(group?.className).toMatch(/rounded-sm/);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ─── Interaction ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
describe('SegmentedControl — click selection', () => {
|
||||||
|
it('clicking an inactive segment calls onChange with its value', async () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(SegmentedControl, { props: { options, value: 'a', onChange } });
|
||||||
|
|
||||||
|
await page.getByRole('radio', { name: 'Option B' }).click();
|
||||||
|
|
||||||
|
expect(onChange).toHaveBeenCalledWith('b');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('clicking the already-active segment still calls onChange', async () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(SegmentedControl, { props: { options, value: 'a', onChange } });
|
||||||
|
|
||||||
|
await page.getByRole('radio', { name: 'Option A' }).click();
|
||||||
|
|
||||||
|
expect(onChange).toHaveBeenCalledWith('a');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ─── Keyboard ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
describe('SegmentedControl — keyboard roving tabindex', () => {
|
||||||
|
it('ArrowRight moves focus and selection to the next segment', async () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(SegmentedControl, { props: { options, value: 'a', onChange } });
|
||||||
|
|
||||||
|
await page.getByRole('radio', { name: 'Option A' }).click();
|
||||||
|
await userEvent.keyboard('{ArrowRight}');
|
||||||
|
|
||||||
|
expect(onChange).toHaveBeenCalledWith('b');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ArrowLeft moves focus to the previous segment', async () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(SegmentedControl, { props: { options, value: 'b', onChange } });
|
||||||
|
|
||||||
|
await page.getByRole('radio', { name: 'Option B' }).click();
|
||||||
|
await userEvent.keyboard('{ArrowLeft}');
|
||||||
|
|
||||||
|
expect(onChange).toHaveBeenCalledWith('a');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ArrowRight wraps from last to first', async () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(SegmentedControl, { props: { options, value: 'c', onChange } });
|
||||||
|
|
||||||
|
await page.getByRole('radio', { name: 'Option C' }).click();
|
||||||
|
await userEvent.keyboard('{ArrowRight}');
|
||||||
|
|
||||||
|
expect(onChange).toHaveBeenCalledWith('a');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ArrowLeft wraps from first to last', async () => {
|
||||||
|
const onChange = vi.fn();
|
||||||
|
render(SegmentedControl, { props: { options, value: 'a', onChange } });
|
||||||
|
|
||||||
|
await page.getByRole('radio', { name: 'Option A' }).click();
|
||||||
|
await userEvent.keyboard('{ArrowLeft}');
|
||||||
|
|
||||||
|
expect(onChange).toHaveBeenCalledWith('c');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// ─── Touch target ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
describe('SegmentedControl — geometry', () => {
|
||||||
|
it('each segment meets the 44px min-height touch target', async () => {
|
||||||
|
render(SegmentedControl, { props: { options, value: 'a', onChange: vi.fn() } });
|
||||||
|
const radios = document.querySelectorAll('[role="radio"]');
|
||||||
|
for (const radio of Array.from(radios)) {
|
||||||
|
expect(radio.className).toMatch(/min-h-\[44px\]/);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('each segment has the px-4 py-[9px] padding classes', async () => {
|
||||||
|
render(SegmentedControl, { props: { options, value: 'a', onChange: vi.fn() } });
|
||||||
|
const radios = document.querySelectorAll('[role="radio"]');
|
||||||
|
for (const radio of Array.from(radios)) {
|
||||||
|
expect(radio.className).toMatch(/px-4/);
|
||||||
|
expect(radio.className).toMatch(/py-\[9px\]/);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { m } from '$lib/paraglide/messages.js';
|
import { m } from '$lib/paraglide/messages.js';
|
||||||
|
import SegmentedControl from './SegmentedControl.svelte';
|
||||||
|
|
||||||
type Theme = 'light' | 'dark';
|
type Theme = 'light' | 'dark';
|
||||||
|
|
||||||
@@ -24,51 +25,31 @@ const themeLabel = $derived(
|
|||||||
theme === 'dark' ? m.theme_toggle_to_light() : m.theme_toggle_to_dark()
|
theme === 'dark' ? m.theme_toggle_to_light() : m.theme_toggle_to_dark()
|
||||||
);
|
);
|
||||||
|
|
||||||
function toggle() {
|
const themeOptions = $derived([
|
||||||
theme = theme === 'dark' ? 'light' : 'dark';
|
{ value: 'light', label: m.theme_segment_light() },
|
||||||
|
{ value: 'dark', label: m.theme_segment_dark() }
|
||||||
|
]);
|
||||||
|
|
||||||
|
function handleChange(next: string) {
|
||||||
|
if (next !== 'light' && next !== 'dark') return;
|
||||||
|
theme = next as Theme;
|
||||||
localStorage.setItem('theme', theme);
|
localStorage.setItem('theme', theme);
|
||||||
document.documentElement.setAttribute('data-theme', theme);
|
document.documentElement.setAttribute('data-theme', theme);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<button
|
<!--
|
||||||
type="button"
|
ThemeToggle — binary light/dark segmented control.
|
||||||
onclick={toggle}
|
File kept at $lib/shared/primitives/ThemeToggle.svelte (required by #862).
|
||||||
aria-label={themeLabel}
|
Boot FOUC prevention: a tiny inline script in <head> reads localStorage['theme']
|
||||||
title={themeLabel}
|
and sets data-theme before paint — that script is unchanged by this refactor.
|
||||||
class="rounded p-1.5 text-white/65 transition-colors hover:bg-white/10 hover:text-white focus:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring"
|
The aria-label on the group communicates the toggle purpose to screen readers.
|
||||||
>
|
-->
|
||||||
{#if theme === 'dark'}
|
<div aria-label={themeLabel} title={themeLabel}>
|
||||||
<!-- Sun icon — click to go light -->
|
<SegmentedControl
|
||||||
<svg
|
options={themeOptions}
|
||||||
class="h-5 w-5"
|
value={theme}
|
||||||
viewBox="0 0 24 24"
|
onChange={handleChange}
|
||||||
fill="none"
|
label={m.theme_toggle_label()}
|
||||||
stroke="currentColor"
|
/>
|
||||||
stroke-width="2"
|
</div>
|
||||||
aria-hidden="true"
|
|
||||||
>
|
|
||||||
<circle cx="12" cy="12" r="4" />
|
|
||||||
<path
|
|
||||||
stroke-linecap="round"
|
|
||||||
d="M12 2v2M12 20v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M2 12h2M20 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
{:else}
|
|
||||||
<!-- Moon icon — click to go dark -->
|
|
||||||
<svg
|
|
||||||
class="h-5 w-5"
|
|
||||||
viewBox="0 0 24 24"
|
|
||||||
fill="none"
|
|
||||||
stroke="currentColor"
|
|
||||||
stroke-width="2"
|
|
||||||
aria-hidden="true"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
stroke-linecap="round"
|
|
||||||
stroke-linejoin="round"
|
|
||||||
d="M21 12.79A9 9 0 1111.21 3 7 7 0 0021 12.79z"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
{/if}
|
|
||||||
</button>
|
|
||||||
|
|||||||
@@ -8,38 +8,59 @@ afterEach(() => {
|
|||||||
localStorage.removeItem('theme');
|
localStorage.removeItem('theme');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('ThemeToggle — label derivation (light mode)', () => {
|
describe('ThemeToggle — renders segments (light mode)', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
localStorage.setItem('theme', 'light');
|
localStorage.setItem('theme', 'light');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('aria-label invites switching to dark mode when theme is light', async () => {
|
it('renders a radiogroup with Hell and Dunkel segments', async () => {
|
||||||
render(ThemeToggle);
|
render(ThemeToggle);
|
||||||
const btn = await page.getByRole('button').element();
|
expect(document.querySelector('[role="radiogroup"]')).not.toBeNull();
|
||||||
expect(btn.getAttribute('aria-label')).toBe('Zu dunklem Design wechseln');
|
await expect.element(page.getByRole('radio', { name: 'Hell' })).toBeVisible();
|
||||||
|
await expect.element(page.getByRole('radio', { name: 'Dunkel' })).toBeVisible();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('title equals aria-label in light mode', async () => {
|
it('Hell segment is aria-checked="true" in light mode', async () => {
|
||||||
render(ThemeToggle);
|
render(ThemeToggle);
|
||||||
const btn = await page.getByRole('button').element();
|
await expect
|
||||||
expect(btn.getAttribute('title')).toBe(btn.getAttribute('aria-label'));
|
.element(page.getByRole('radio', { name: 'Hell' }))
|
||||||
|
.toHaveAttribute('aria-checked', 'true');
|
||||||
|
await expect
|
||||||
|
.element(page.getByRole('radio', { name: 'Dunkel' }))
|
||||||
|
.toHaveAttribute('aria-checked', 'false');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('ThemeToggle — label derivation (dark mode)', () => {
|
describe('ThemeToggle — renders segments (dark mode)', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
localStorage.setItem('theme', 'dark');
|
localStorage.setItem('theme', 'dark');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('aria-label invites switching to light mode when theme is dark', async () => {
|
it('Dunkel segment is aria-checked="true" in dark mode', async () => {
|
||||||
render(ThemeToggle);
|
render(ThemeToggle);
|
||||||
const btn = await page.getByRole('button').element();
|
await expect
|
||||||
expect(btn.getAttribute('aria-label')).toBe('Zu hellem Design wechseln');
|
.element(page.getByRole('radio', { name: 'Dunkel' }))
|
||||||
});
|
.toHaveAttribute('aria-checked', 'true');
|
||||||
|
await expect
|
||||||
it('title equals aria-label in dark mode', async () => {
|
.element(page.getByRole('radio', { name: 'Hell' }))
|
||||||
render(ThemeToggle);
|
.toHaveAttribute('aria-checked', 'false');
|
||||||
const btn = await page.getByRole('button').element();
|
});
|
||||||
expect(btn.getAttribute('title')).toBe(btn.getAttribute('aria-label'));
|
});
|
||||||
|
|
||||||
|
describe('ThemeToggle — theme switching', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
localStorage.setItem('theme', 'light');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('clicking Dunkel sets data-theme=dark on documentElement', async () => {
|
||||||
|
render(ThemeToggle);
|
||||||
|
await page.getByRole('radio', { name: 'Dunkel' }).click();
|
||||||
|
expect(document.documentElement.getAttribute('data-theme')).toBe('dark');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('clicking Dunkel persists theme in localStorage', async () => {
|
||||||
|
render(ThemeToggle);
|
||||||
|
await page.getByRole('radio', { name: 'Dunkel' }).click();
|
||||||
|
expect(localStorage.getItem('theme')).toBe('dark');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -42,14 +42,16 @@ function reset() {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#snippet layerToggle(label: string, testid: string, pressed: boolean, toggle: () => void)}
|
{#snippet layerToggle(label: string, testid: string, pressed: boolean, toggle: () => void)}
|
||||||
|
<!-- §6 re-skin: bg-primary/text-primary-fg (active) · bg-surface/text-ink-2 (inactive)
|
||||||
|
Typography: Montserrat 12px/700 tracking-[.08em] UPPERCASE; min-h-[44px] touch target -->
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
data-testid={testid}
|
data-testid={testid}
|
||||||
aria-pressed={pressed}
|
aria-pressed={pressed}
|
||||||
onclick={toggle}
|
onclick={toggle}
|
||||||
class="inline-flex min-h-[44px] items-center gap-2 rounded border px-3 font-sans text-sm transition-colors {pressed
|
class="inline-flex min-h-[44px] items-center gap-2 rounded-sm border px-4 py-[9px] font-sans text-xs font-bold tracking-[.08em] uppercase transition-colors focus-visible:ring-2 focus-visible:ring-focus-ring focus-visible:outline-none {pressed
|
||||||
? 'border-primary bg-primary text-primary-fg'
|
? 'border-primary bg-primary text-primary-fg'
|
||||||
: 'border-line bg-muted text-ink-2 hover:bg-line'}"
|
: 'hover:bg-surface-2 border-line bg-surface text-ink-2'}"
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
@@ -73,7 +75,7 @@ function reset() {
|
|||||||
aria-expanded={open}
|
aria-expanded={open}
|
||||||
aria-controls={open ? 'timeline-filter-panel' : undefined}
|
aria-controls={open ? 'timeline-filter-panel' : undefined}
|
||||||
onclick={() => (open = !open)}
|
onclick={() => (open = !open)}
|
||||||
class="inline-flex min-h-[44px] items-center gap-2 rounded border border-line bg-surface px-4 font-sans text-xs font-bold tracking-widest text-ink-2 uppercase transition-colors hover:bg-muted"
|
class="hover:bg-surface-2 inline-flex min-h-[44px] items-center gap-2 rounded-sm border border-line bg-surface px-4 font-sans text-xs font-bold tracking-[.08em] text-ink-2 uppercase transition-colors"
|
||||||
>
|
>
|
||||||
{hiddenCount === 0
|
{hiddenCount === 0
|
||||||
? m.timeline_filter_trigger()
|
? m.timeline_filter_trigger()
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { m } from '$lib/paraglide/messages.js';
|
import { m } from '$lib/paraglide/messages.js';
|
||||||
import { radioGroupNav } from '$lib/shared/actions/radioGroupNav';
|
import SegmentedControl from '$lib/shared/primitives/SegmentedControl.svelte';
|
||||||
|
|
||||||
type GeschichteType = 'STORY' | 'JOURNEY';
|
type GeschichteType = 'STORY' | 'JOURNEY';
|
||||||
|
|
||||||
const TYPES: GeschichteType[] = ['STORY', 'JOURNEY'];
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onweiter: (type: GeschichteType) => void;
|
onweiter: (type: GeschichteType) => void;
|
||||||
}
|
}
|
||||||
@@ -15,10 +13,6 @@ let { onweiter }: Props = $props();
|
|||||||
let selected = $state<GeschichteType | null>(null);
|
let selected = $state<GeschichteType | null>(null);
|
||||||
let announcement = $state('');
|
let announcement = $state('');
|
||||||
|
|
||||||
// Roving-tabindex holder: falls back to the first card so keyboard nav can start
|
|
||||||
// even when nothing is selected (all cards at tabindex=-1 would be a keyboard dead-spot).
|
|
||||||
const rovingFocusType = $derived(selected ?? TYPES[0]);
|
|
||||||
|
|
||||||
function select(type: GeschichteType) {
|
function select(type: GeschichteType) {
|
||||||
selected = type;
|
selected = type;
|
||||||
announcement = '';
|
announcement = '';
|
||||||
@@ -32,15 +26,10 @@ function handleWeiter() {
|
|||||||
onweiter(selected);
|
onweiter(selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
const titles: Record<GeschichteType, () => string> = {
|
const typeOptions = [
|
||||||
STORY: m.journey_selector_story_title,
|
{ value: 'STORY', label: m.journey_selector_story_title() },
|
||||||
JOURNEY: m.journey_selector_journey_title
|
{ value: 'JOURNEY', label: m.journey_selector_journey_title() }
|
||||||
};
|
];
|
||||||
|
|
||||||
const descs: Record<GeschichteType, () => string> = {
|
|
||||||
STORY: m.journey_selector_story_desc,
|
|
||||||
JOURNEY: m.journey_selector_journey_desc
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
@@ -48,31 +37,14 @@ const descs: Record<GeschichteType, () => string> = {
|
|||||||
{m.journey_selector_question()}
|
{m.journey_selector_question()}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div
|
<SegmentedControl
|
||||||
role="radiogroup"
|
options={typeOptions}
|
||||||
aria-labelledby="type-selector-label"
|
value={selected ?? ''}
|
||||||
class="grid grid-cols-1 gap-4 sm:grid-cols-2"
|
onChange={(v) => {
|
||||||
use:radioGroupNav={(v) => {
|
if (v === 'STORY' || v === 'JOURNEY') select(v);
|
||||||
if (TYPES.includes(v as GeschichteType)) select(v as GeschichteType);
|
|
||||||
}}
|
}}
|
||||||
>
|
label={m.journey_selector_question()}
|
||||||
{#each TYPES as type (type)}
|
/>
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
role="radio"
|
|
||||||
value={type}
|
|
||||||
aria-checked={selected === type}
|
|
||||||
tabindex={type === rovingFocusType ? 0 : -1}
|
|
||||||
onclick={() => select(type)}
|
|
||||||
class="min-h-[64px] cursor-pointer rounded border px-4 py-3 text-left transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-focus-ring {selected === type
|
|
||||||
? 'border-primary bg-primary text-primary-fg'
|
|
||||||
: 'border-line bg-surface text-ink hover:border-primary/50'}"
|
|
||||||
>
|
|
||||||
<span class="block font-sans text-sm font-bold">{titles[type]()}</span>
|
|
||||||
<span class="mt-1 block font-sans text-xs text-current opacity-70">{descs[type]()}</span>
|
|
||||||
</button>
|
|
||||||
{/each}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div aria-live="polite" aria-atomic="true" class="sr-only">{announcement}</div>
|
<div aria-live="polite" aria-atomic="true" class="sr-only">{announcement}</div>
|
||||||
|
|
||||||
|
|||||||
@@ -18,13 +18,18 @@ describe('TypeSelector', () => {
|
|||||||
await expect.element(page.getByRole('radio', { name: /Lesereise/i })).toBeVisible();
|
await expect.element(page.getByRole('radio', { name: /Lesereise/i })).toBeVisible();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('radiogroup is correctly labelled', async () => {
|
it('radiogroup is correctly labelled (via aria-label or aria-labelledby)', async () => {
|
||||||
render(TypeSelector, { props: { onweiter: vi.fn() } });
|
render(TypeSelector, { props: { onweiter: vi.fn() } });
|
||||||
|
|
||||||
const group = document.querySelector('[role="radiogroup"]');
|
const group = document.querySelector('[role="radiogroup"]');
|
||||||
const labelledBy = group?.getAttribute('aria-labelledby');
|
// SegmentedControl uses aria-label; the old TypeSelector used aria-labelledby.
|
||||||
|
// Accept either as long as the accessible name is non-empty.
|
||||||
|
const ariaLabel = group?.getAttribute('aria-label') ?? '';
|
||||||
|
const labelledBy = group?.getAttribute('aria-labelledby') ?? '';
|
||||||
const labelEl = labelledBy ? document.getElementById(labelledBy) : null;
|
const labelEl = labelledBy ? document.getElementById(labelledBy) : null;
|
||||||
expect(labelEl?.textContent?.trim().length).toBeGreaterThan(0);
|
const hasAccessibleName =
|
||||||
|
ariaLabel.trim().length > 0 || (labelEl?.textContent?.trim().length ?? 0) > 0;
|
||||||
|
expect(hasAccessibleName).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Weiter button has aria-disabled=true when nothing is selected', async () => {
|
it('Weiter button has aria-disabled=true when nothing is selected', async () => {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { m } from '$lib/paraglide/messages.js';
|
|||||||
import { SvelteMap } from 'svelte/reactivity';
|
import { SvelteMap } from 'svelte/reactivity';
|
||||||
import BackButton from '$lib/shared/primitives/BackButton.svelte';
|
import BackButton from '$lib/shared/primitives/BackButton.svelte';
|
||||||
import PersonCard from './PersonCard.svelte';
|
import PersonCard from './PersonCard.svelte';
|
||||||
import MetaLine from '$lib/shared/primitives/MetaLine.svelte';
|
|
||||||
import NameHistoryCard from './NameHistoryCard.svelte';
|
import NameHistoryCard from './NameHistoryCard.svelte';
|
||||||
import CoCorrespondentsList from './CoCorrespondentsList.svelte';
|
import CoCorrespondentsList from './CoCorrespondentsList.svelte';
|
||||||
import PersonDocumentList from './PersonDocumentList.svelte';
|
import PersonDocumentList from './PersonDocumentList.svelte';
|
||||||
@@ -16,16 +15,6 @@ const person = $derived(data.person);
|
|||||||
const sentDocuments = $derived(data.sentDocuments);
|
const sentDocuments = $derived(data.sentDocuments);
|
||||||
const receivedDocuments = $derived(data.receivedDocuments);
|
const receivedDocuments = $derived(data.receivedDocuments);
|
||||||
|
|
||||||
const totalDocCount = $derived(sentDocuments.length + receivedDocuments.length);
|
|
||||||
const relCount = $derived(data.relationships.length + data.inferredRelationships.length);
|
|
||||||
|
|
||||||
const personMetaItems = $derived.by(() => {
|
|
||||||
const items: string[] = [];
|
|
||||||
if (totalDocCount > 0) items.push(m.person_meta_doc_count({ count: totalDocCount }));
|
|
||||||
if (relCount > 0) items.push(m.person_meta_rel_count({ count: relCount }));
|
|
||||||
return items;
|
|
||||||
});
|
|
||||||
|
|
||||||
const coCorrespondents = $derived.by(() => {
|
const coCorrespondents = $derived.by(() => {
|
||||||
const freq = new SvelteMap<string, { id: string; name: string; count: number }>();
|
const freq = new SvelteMap<string, { id: string; name: string; count: number }>();
|
||||||
|
|
||||||
@@ -72,11 +61,6 @@ const coCorrespondents = $derived.by(() => {
|
|||||||
<!-- Left column: Person card + name history -->
|
<!-- Left column: Person card + name history -->
|
||||||
<div>
|
<div>
|
||||||
<PersonCard person={person} canWrite={data.canWrite} />
|
<PersonCard person={person} canWrite={data.canWrite} />
|
||||||
{#if personMetaItems.length > 0}
|
|
||||||
<div class="mt-3">
|
|
||||||
<MetaLine items={personMetaItems} />
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
<div class="mt-6">
|
<div class="mt-6">
|
||||||
<NameHistoryCard aliases={data.aliases} personFirstName={person.firstName} />
|
<NameHistoryCard aliases={data.aliases} personFirstName={person.firstName} />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user