feat(frontend): UX review followups — primitives + a11y/UX fixes across 4 passes
New shared primitives: - Toaster + toast-store, ConfirmSheet, Modal, focusTrap action, pullToRefresh action, avatarPalette + initials helper, Skeleton, HeartBurst, haptics, export-status store with onClearAuth hook Critical UX/a11y: - Replaced window.confirm with branded ConfirmSheet - Focus management + Escape on every modal (PIN, Lightbox, Onboarding, ContextSheet, data-mode sheet, leave-confirm, HTML guide, host/admin ban + PIN-display modals) - Sheet backdrops are real buttons with aria-label - Silent ApiError catches now surface via global Toaster Major polish: - Dark-mode parity on HashtagChips + avatars (shared palette) - Conditional Export tab in BottomNav (badge dot when ZIP ready) - Back chevrons on /recover (history-aware) and /export - Upload composer discard confirmation when content is staged - Camera segmented Photo/Video shutter - PIN auto-submit on 4th digit, paste-flash-free (controlled input) - Welcome-back toast on /feed after PIN recovery Minor: - Skeleton states on feed; pull-to-refresh with live drag indicator - Haptics on like / capture / submit / PIN-copy / onboarding complete - Comment 500-char counter; quota "Fast voll" / "Limit erreicht" labels - Onboarding pip ≥24px tap targets; long-press hint step - overscroll-behavior lock on <html> while feed mounted - teardownExportStatus wired via onClearAuth (covers 401 + explicit logout) - ConfirmSheet per-instance titleId; Modal requires titleId or ariaLabel Tests (7 new Playwright specs): - 01-auth/pin-auto-submit, 01-auth/back-chevron - 03-feed/confirm-sheet-delete, 03-feed/toast-on-failure - 09-mobile/focus-trap, 09-mobile/sheet-escape, 09-mobile/upload-cancel-confirm FOLLOWUPS.md captures the deferred AT inert containment work with acceptance criteria + implementation sketches. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
84
frontend/src/lib/actions/focus-trap.ts
Normal file
84
frontend/src/lib/actions/focus-trap.ts
Normal file
@@ -0,0 +1,84 @@
|
||||
// Focus management for modals/sheets. On mount: focuses the first focusable
|
||||
// (or the node itself) and stores the previously-focused element. Tab/Shift+Tab
|
||||
// wrap inside the node. Escape calls `onclose` when set. On destroy: restores
|
||||
// focus to the originating element so screen-reader / keyboard users land back
|
||||
// where they were.
|
||||
|
||||
import type { ActionReturn } from 'svelte/action';
|
||||
|
||||
export interface FocusTrapOptions {
|
||||
onclose?: () => void;
|
||||
closeOnEscape?: boolean;
|
||||
/** When true, focus the first focusable on mount. Defaults true. */
|
||||
autoFocus?: boolean;
|
||||
}
|
||||
|
||||
const FOCUSABLE =
|
||||
'a[href], area[href], input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, [tabindex]:not([tabindex="-1"]), [contenteditable="true"]';
|
||||
|
||||
function focusables(root: HTMLElement): HTMLElement[] {
|
||||
return Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE)).filter(
|
||||
(el) => !el.hasAttribute('disabled') && el.offsetParent !== null
|
||||
);
|
||||
}
|
||||
|
||||
export function focusTrap(
|
||||
node: HTMLElement,
|
||||
options: FocusTrapOptions = {}
|
||||
): ActionReturn<FocusTrapOptions> {
|
||||
let opts = options;
|
||||
const previouslyFocused = (typeof document !== 'undefined' ? document.activeElement : null) as HTMLElement | null;
|
||||
|
||||
function onKeyDown(e: KeyboardEvent) {
|
||||
if (e.key === 'Escape' && opts.closeOnEscape !== false && opts.onclose) {
|
||||
e.preventDefault();
|
||||
opts.onclose();
|
||||
return;
|
||||
}
|
||||
if (e.key !== 'Tab') return;
|
||||
const list = focusables(node);
|
||||
if (list.length === 0) {
|
||||
e.preventDefault();
|
||||
node.focus();
|
||||
return;
|
||||
}
|
||||
const first = list[0];
|
||||
const last = list[list.length - 1];
|
||||
const active = document.activeElement as HTMLElement | null;
|
||||
if (e.shiftKey) {
|
||||
if (active === first || !node.contains(active)) {
|
||||
e.preventDefault();
|
||||
last.focus();
|
||||
}
|
||||
} else {
|
||||
if (active === last) {
|
||||
e.preventDefault();
|
||||
first.focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
node.addEventListener('keydown', onKeyDown);
|
||||
|
||||
if (opts.autoFocus !== false) {
|
||||
// Defer one frame so the element is fully laid out (sheets animate in).
|
||||
requestAnimationFrame(() => {
|
||||
const list = focusables(node);
|
||||
const target = list[0] ?? node;
|
||||
if (!node.hasAttribute('tabindex')) node.setAttribute('tabindex', '-1');
|
||||
target.focus({ preventScroll: true });
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
update(newOptions) {
|
||||
opts = newOptions;
|
||||
},
|
||||
destroy() {
|
||||
node.removeEventListener('keydown', onKeyDown);
|
||||
if (previouslyFocused && typeof previouslyFocused.focus === 'function') {
|
||||
try { previouslyFocused.focus({ preventScroll: true }); } catch { /* element may have unmounted */ }
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
82
frontend/src/lib/actions/pull-to-refresh.ts
Normal file
82
frontend/src/lib/actions/pull-to-refresh.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
// Pull-to-refresh gesture. Only engages when the page is scrolled to the top.
|
||||
// Calls `onrefresh` once `threshold` px of overscroll have been pulled. The
|
||||
// element should set `overscroll-behavior-y: contain` so the browser doesn't
|
||||
// hijack the gesture (mobile Chrome's built-in refresh).
|
||||
//
|
||||
// `onpull` fires during the drag with `delta` (px pulled, clamped ≥ 0) and a
|
||||
// `progress` ratio (0–1+). Consumers can use it to render a growing indicator
|
||||
// that closes the visual loop before the refresh actually starts.
|
||||
|
||||
import type { ActionReturn } from 'svelte/action';
|
||||
|
||||
export interface PullToRefreshOptions {
|
||||
onrefresh: () => void | Promise<void>;
|
||||
onpull?: (delta: number, progress: number) => void;
|
||||
threshold?: number;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export function pullToRefresh(
|
||||
node: HTMLElement,
|
||||
options: PullToRefreshOptions
|
||||
): ActionReturn<PullToRefreshOptions> {
|
||||
let opts = options;
|
||||
let startY = 0;
|
||||
let pulling = false;
|
||||
let triggered = false;
|
||||
|
||||
function scroller(): HTMLElement | (Window & typeof globalThis) {
|
||||
return node.scrollHeight > node.clientHeight ? node : window;
|
||||
}
|
||||
|
||||
function scrollTop(): number {
|
||||
const s = scroller();
|
||||
return s instanceof Window ? window.scrollY : s.scrollTop;
|
||||
}
|
||||
|
||||
function reportPull(delta: number) {
|
||||
if (!opts.onpull) return;
|
||||
const threshold = opts.threshold ?? 60;
|
||||
opts.onpull(Math.max(0, delta), Math.max(0, delta) / threshold);
|
||||
}
|
||||
|
||||
function onTouchStart(e: TouchEvent) {
|
||||
if (opts.disabled) return;
|
||||
if (scrollTop() > 0) return;
|
||||
startY = e.touches[0].clientY;
|
||||
pulling = true;
|
||||
triggered = false;
|
||||
}
|
||||
|
||||
function onTouchMove(e: TouchEvent) {
|
||||
if (!pulling || triggered) return;
|
||||
const delta = e.touches[0].clientY - startY;
|
||||
reportPull(delta);
|
||||
if (delta > (opts.threshold ?? 60)) {
|
||||
triggered = true;
|
||||
void opts.onrefresh();
|
||||
}
|
||||
}
|
||||
|
||||
function onTouchEnd() {
|
||||
if (pulling && !triggered) reportPull(0);
|
||||
pulling = false;
|
||||
}
|
||||
|
||||
node.addEventListener('touchstart', onTouchStart, { passive: true });
|
||||
node.addEventListener('touchmove', onTouchMove, { passive: true });
|
||||
node.addEventListener('touchend', onTouchEnd);
|
||||
node.addEventListener('touchcancel', onTouchEnd);
|
||||
|
||||
return {
|
||||
update(newOptions) {
|
||||
opts = newOptions;
|
||||
},
|
||||
destroy() {
|
||||
node.removeEventListener('touchstart', onTouchStart);
|
||||
node.removeEventListener('touchmove', onTouchMove);
|
||||
node.removeEventListener('touchend', onTouchEnd);
|
||||
node.removeEventListener('touchcancel', onTouchEnd);
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user