Accessibility pass, WCAG 2.2 AA (1.50.0)

Public pages, auth, registration, payment, My Events and the kiosk: skip
link, focus ring, labels tied to fields, named quantity buttons, announced
errors, ModalOverlay popups (focus trap, Escape, focus return), contrast
and underlined in-text links, reduced motion. Branding warns about a primary
colour too light for white text and offers a darker shade. axe-core and
keyboard checks in e2e/accessibility.spec.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-28 15:41:19 +02:00
co-authored by Claude Opus 5.5
parent eac21f3860
commit 9548efdb45
57 changed files with 793 additions and 256 deletions
@@ -2,7 +2,7 @@
import React, { useMemo, useState } from "react";
import { Monitor, Smartphone, RefreshCw } from "lucide-react";
import { buildBrandScale, buildSecondaryTokens, buildAccentTokens, contrastForeground, isValidHex } from "@/lib/colorScale";
import { accessiblePrimary, buildBrandScale, buildSecondaryTokens, buildAccentTokens, contrastForeground, contrastRatio, isValidHex, MIN_TEXT_CONTRAST } from "@/lib/colorScale";
type View = "website" | "email";
type Viewport = "desktop" | "mobile";
@@ -15,9 +15,11 @@ type Viewport = "desktop" | "mobile";
* page's own theme while the admin is still experimenting with colors.
*/
export function BrandingPreviewPanel({
primaryColor, secondaryColor, accentColor, logoSrc, orgName, orgTagline,
primaryColor, secondaryColor, accentColor, logoSrc, orgName, orgTagline, onUsePrimary,
}: {
primaryColor: string;
/** Offered when the primary colour is too light to read: switches to a darker shade. */
onUsePrimary?: (hex: string) => void;
secondaryColor: string;
accentColor: string;
logoSrc: string | null;
@@ -35,9 +37,29 @@ export function BrandingPreviewPanel({
const secondary = useMemo(() => buildSecondaryTokens(safeSecondary), [safeSecondary]);
const accent = useMemo(() => buildAccentTokens(safeAccent), [safeAccent]);
const primaryFg = useMemo(() => contrastForeground(safePrimary), [safePrimary]);
const primaryContrast = useMemo(() => contrastRatio(safePrimary, "#ffffff"), [safePrimary]);
const suggested = useMemo(() => accessiblePrimary(safePrimary), [safePrimary]);
return (
<div className="border rounded-xl bg-white shadow-sm overflow-hidden">
{primaryContrast < MIN_TEXT_CONTRAST && (
<div role="status" className="px-4 py-3 border-b bg-amber-50 text-sm text-amber-900 flex flex-wrap items-center gap-x-3 gap-y-2">
<p className="flex-1 min-w-[12rem]">
This primary colour is too light for white text and links to be easy to read
({primaryContrast.toFixed(1)}:1 — at least {MIN_TEXT_CONTRAST}:1 is needed for accessibility).
</p>
{onUsePrimary && (
<button
type="button"
onClick={() => onUsePrimary(suggested)}
className="inline-flex items-center gap-2 rounded-lg border border-amber-300 bg-white px-3 py-1.5 text-xs font-medium hover:bg-amber-100"
>
<span className="w-4 h-4 rounded border" style={{ background: suggested }} aria-hidden="true" />
Use a darker shade ({suggested.toUpperCase()})
</button>
)}
</div>
)}
<div className="flex items-center justify-between px-4 py-3 border-b bg-gray-50">
<div>
<h3 className="text-sm font-semibold text-gray-900">Live Preview</h3>
@@ -129,8 +129,9 @@ export function LoginForm() {
</div>
<div>
<label className="block text-sm font-medium mb-1">Verification code</label>
<label htmlFor="login-code" className="block text-sm font-medium mb-1">Verification code</label>
<input
id="login-code"
type="text"
inputMode="numeric"
autoComplete="one-time-code"
@@ -153,7 +154,7 @@ export function LoginForm() {
<span>Trust this device for 30 days. Only tick this on a device that&apos;s yours.</span>
</label>
{error && <p className="text-sm text-red-600">{error}</p>}
{error && <p role="alert" className="text-sm text-red-600">{error}</p>}
<button
type="submit"
@@ -188,8 +189,10 @@ export function LoginForm() {
</p>
)}
<div>
<label className="block text-sm font-medium mb-1">Email or phone</label>
<label htmlFor="login-email" className="block text-sm font-medium mb-1">Email or phone</label>
<input
id="login-email"
autoComplete="username"
type="text"
value={email}
onChange={(e) => setEmail(e.target.value)}
@@ -199,9 +202,11 @@ export function LoginForm() {
</div>
<div>
<label className="block text-sm font-medium mb-1">Password</label>
<label htmlFor="login-password" className="block text-sm font-medium mb-1">Password</label>
<div className="relative">
<input
id="login-password"
autoComplete="current-password"
type={showPassword ? "text" : "password"}
value={password}
onChange={(e) => setPassword(e.target.value)}
@@ -211,7 +216,7 @@ export function LoginForm() {
<button
type="button"
onClick={() => setShowPassword((s) => !s)}
className="absolute right-2 top-1/2 -translate-y-1/2 text-sm text-brand-600"
className="absolute right-1 top-1/2 -translate-y-1/2 text-sm text-brand-600 px-2 py-1 min-h-6"
aria-label={showPassword ? "Hide password" : "Show password"}
>
{showPassword ? "Hide" : "Show"}
@@ -236,7 +241,7 @@ export function LoginForm() {
</div>
{error && (
<div className="text-sm text-red-600">
<div role="alert" className="text-sm text-red-600">
<p>{error}</p>
{error.toLowerCase().includes('not yet active') && (
<p className="mt-1 text-gray-600">Check your inbox for an activation email. If you didn&apos;t receive it, try logging in again to resend it.</p>
@@ -257,7 +262,7 @@ export function LoginForm() {
<Link
href="/legal/terms"
target="_blank"
className="text-brand-600 hover:underline"
className="text-brand-700 underline hover:no-underline"
>
Terms of Use
</Link>{" "}
@@ -265,7 +270,7 @@ export function LoginForm() {
<Link
href="/legal/privacy"
target="_blank"
className="text-brand-600 hover:underline"
className="text-brand-700 underline hover:no-underline"
>
Privacy Policy
</Link>.
@@ -68,8 +68,10 @@ export function RegisterForm() {
return (
<form onSubmit={onSubmit} className="space-y-4 max-w-sm w-full">
<div>
<label className="block text-sm font-medium mb-1">Full Name</label>
<label htmlFor="signup-full-name" className="block text-sm font-medium mb-1">Full Name</label>
<input
id="signup-full-name"
autoComplete="name"
value={name}
onChange={(e) => setName(e.target.value)}
className="w-full border rounded px-3 py-2"
@@ -78,8 +80,10 @@ export function RegisterForm() {
</div>
<div>
<label className="block text-sm font-medium mb-1">Email</label>
<label htmlFor="signup-email" className="block text-sm font-medium mb-1">Email</label>
<input
id="signup-email"
autoComplete="email"
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
@@ -89,8 +93,10 @@ export function RegisterForm() {
</div>
<div>
<label className="block text-sm font-medium mb-1">Password</label>
<label htmlFor="signup-password" className="block text-sm font-medium mb-1">Password</label>
<input
id="signup-password"
autoComplete="new-password"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
@@ -100,8 +106,11 @@ export function RegisterForm() {
</div>
<div>
<label className="block text-sm font-medium mb-1">Phone Number (optional)</label>
<label htmlFor="signup-phone-number" className="block text-sm font-medium mb-1">Phone Number (optional)</label>
<input
id="signup-phone-number"
type="tel"
autoComplete="tel"
value={phoneNumber}
onChange={(e) => setPhoneNumber(e.target.value)}
placeholder="e.g. 082 123 4567"
@@ -111,8 +120,9 @@ export function RegisterForm() {
{hasValidPhone && (
<div>
<label className="block text-sm font-medium mb-1">Notification Preference</label>
<label htmlFor="signup-notification-preference" className="block text-sm font-medium mb-1">Notification Preference</label>
<select
id="signup-notification-preference"
value={notificationPreference}
onChange={(e) => setNotificationPreference(e.target.value as "email" | "whatsapp" | "both")}
className="w-full border rounded px-3 py-2"
@@ -138,7 +148,7 @@ export function RegisterForm() {
<Link
href="/legal/terms"
target="_blank"
className="text-brand-600 hover:underline"
className="text-brand-700 underline hover:no-underline"
>
Terms of Use
</Link>{" "}
@@ -146,7 +156,7 @@ export function RegisterForm() {
<Link
href="/legal/privacy"
target="_blank"
className="text-brand-600 hover:underline"
className="text-brand-700 underline hover:no-underline"
>
Privacy Policy
</Link>.
@@ -175,7 +185,7 @@ export function RegisterForm() {
</a>
</div>
{error && <p className="text-sm text-red-600">{error}</p>}
{error && <p role="alert" className="text-sm text-red-600">{error}</p>}
<button
type="submit"
@@ -2,6 +2,7 @@
import { useState } from "react";
import { X, Phone, Mail, User } from "lucide-react";
import { ModalOverlay } from "@/components/shared/ModalOverlay";
type ContactButtonProps = {
contactName?: string | null;
@@ -25,15 +26,17 @@ export function ContactButton({ contactName, contactPhone, contactEmail, classNa
{label}
</button>
{open && (
<div
<ModalOverlay
labelledBy="contact-title"
onClose={() => setOpen(false)}
closeOnBackdrop
className="fixed inset-0 bg-black/40 flex items-center justify-center z-50"
onClick={() => setOpen(false)}
>
<div className="bg-white rounded-lg shadow-lg max-w-sm w-full mx-4 p-5" onClick={e => e.stopPropagation()}>
<div className="bg-white rounded-lg shadow-lg max-w-sm w-full mx-4 p-5">
<div className="flex items-center justify-between mb-3">
<h3 className="text-lg font-semibold">Contact us</h3>
<h3 id="contact-title" className="text-lg font-semibold">Contact us</h3>
<button
className="p-1 rounded hover:bg-gray-100 text-gray-500"
className="p-1.5 rounded hover:bg-gray-100 text-gray-500"
onClick={() => setOpen(false)}
aria-label="Close"
>
@@ -44,19 +47,19 @@ export function ContactButton({ contactName, contactPhone, contactEmail, classNa
<div className="space-y-2 text-sm">
{contactName && (
<div className="flex items-center gap-2 text-gray-800">
<User className="w-4 h-4 text-gray-400 shrink-0" />
<User className="w-4 h-4 text-gray-500 shrink-0" />
<span>{contactName}</span>
</div>
)}
{contactPhone && (
<div className="flex items-center gap-2">
<Phone className="w-4 h-4 text-gray-400 shrink-0" />
<Phone className="w-4 h-4 text-gray-500 shrink-0" />
<a href={`tel:${contactPhone}`} className="text-brand-600 hover:underline">{contactPhone}</a>
</div>
)}
{contactEmail && (
<div className="flex items-center gap-2">
<Mail className="w-4 h-4 text-gray-400 shrink-0" />
<Mail className="w-4 h-4 text-gray-500 shrink-0" />
<a href={`mailto:${contactEmail}`} className="text-brand-600 hover:underline">{contactEmail}</a>
</div>
)}
@@ -65,7 +68,7 @@ export function ContactButton({ contactName, contactPhone, contactEmail, classNa
<p className="text-sm text-gray-500">No contact details have been provided for this event.</p>
)}
</div>
</div>
</ModalOverlay>
)}
</>
);
@@ -5,6 +5,7 @@ import { ListPlus, X } from "lucide-react";
import { apiFetch, ApiError } from "@/lib/api";
import { useAuth } from "@/hooks/useAuth";
import type { WaitlistLine } from "@/lib/waitlist";
import { ModalOverlay } from "@/components/shared/ModalOverlay";
export type { WaitlistLine };
@@ -72,11 +73,11 @@ export function JoinWaitlistButton({ eventId, lines, guestsAllowed, initialLine,
</button>
{open && (
<div className="fixed inset-0 z-50 bg-black/40 flex items-center justify-center p-4" onClick={() => setOpen(false)}>
<form onSubmit={submit} className="bg-white rounded-xl shadow-xl w-full max-w-md p-5 space-y-4" onClick={e => e.stopPropagation()}>
<ModalOverlay labelledBy="waitlist-title" onClose={() => setOpen(false)} closeOnBackdrop className="fixed inset-0 z-50 bg-black/40 flex items-center justify-center p-4">
<form onSubmit={submit} className="bg-white rounded-xl shadow-xl w-full max-w-md p-5 space-y-4">
<div className="flex items-center justify-between">
<h2 className="font-semibold">Join the waitlist</h2>
<button type="button" onClick={() => setOpen(false)} aria-label="Close"><X className="w-5 h-5 text-gray-500" /></button>
<h2 id="waitlist-title" className="font-semibold">Join the waitlist</h2>
<button type="button" onClick={() => setOpen(false)} aria-label="Close" className="p-1 rounded hover:bg-gray-100"><X className="w-5 h-5 text-gray-500" /></button>
</div>
{done ? (
@@ -93,16 +94,16 @@ export function JoinWaitlistButton({ eventId, lines, guestsAllowed, initialLine,
<p className="text-sm text-gray-600">If a place opens up, we&apos;ll email or WhatsApp you a link to claim it. We hold it for you for a limited time.</p>
{lines.length > 1 && (
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">Ticket</label>
<select className={inputCls} value={lineKey} onChange={e => setLineKey(e.target.value)}>
<label htmlFor="waitlist-ticket" className="block text-sm font-medium text-gray-700 mb-1">Ticket</label>
<select id="waitlist-ticket" className={inputCls} value={lineKey} onChange={e => setLineKey(e.target.value)}>
{lines.map(l => <option key={keyOf(l)} value={keyOf(l)}>{l.label}</option>)}
</select>
</div>
)}
{lines.length === 1 && <p className="text-sm"><span className="text-gray-500">Ticket:</span> {line.label}</p>}
<div>
<label className="block text-sm font-medium text-gray-700 mb-1">How many?</label>
<input type="number" min={1} max={20} className={`${inputCls} w-24`} value={qty} onChange={e => setQty(Math.max(1, Math.min(20, parseInt(e.target.value, 10) || 1)))} />
<label htmlFor="waitlist-qty" className="block text-sm font-medium text-gray-700 mb-1">How many?</label>
<input id="waitlist-qty" type="number" min={1} max={20} className={`${inputCls} w-24`} value={qty} onChange={e => setQty(Math.max(1, Math.min(20, parseInt(e.target.value, 10) || 1)))} />
</div>
{!loggedIn && (
<div className="space-y-2">
@@ -111,14 +112,14 @@ export function JoinWaitlistButton({ eventId, lines, guestsAllowed, initialLine,
<input type="tel" className={inputCls} placeholder="Phone (optional)" value={guest.phone} onChange={e => setGuest({ ...guest, phone: e.target.value })} aria-label="Phone" />
</div>
)}
{error && <p className="text-sm text-red-600">{error}</p>}
{error && <p role="alert" className="text-sm text-red-600">{error}</p>}
<button type="submit" disabled={busy} className="w-full px-4 py-2 rounded-lg bg-brand-600 text-white text-sm font-medium hover:bg-brand-700 disabled:opacity-50">
{busy ? "Joining…" : "Join waitlist"}
</button>
</>
)}
</form>
</div>
</ModalOverlay>
)}
</>
);
@@ -7,7 +7,7 @@ export function LocationMap({ address, className }: { address?: string | null; c
<div className={className}>
<div className="flex items-start justify-between gap-3">
<p className="text-sm text-gray-700 flex items-start gap-1.5">
<MapPin className="w-4 h-4 shrink-0 mt-0.5 text-gray-400" />
<MapPin className="w-4 h-4 shrink-0 mt-0.5 text-gray-500" />
<span>{address}</span>
</p>
<a
@@ -34,7 +34,7 @@ export function SessionPicker({ event, option, selected, onChange, quantity = 1,
const full = s.left !== null && s.left < Math.max(1, quantity);
const name = sessionLabel(s, event.sessions);
return (
<div key={s.id} className={`flex items-center gap-2 rounded border px-2 py-1.5 text-sm ${full ? "bg-gray-50 text-gray-400" : selected.includes(s.id) ? "border-brand-300 bg-brand-50" : "hover:bg-gray-50"}`}>
<div key={s.id} className={`flex items-center gap-2 rounded border px-2 py-1.5 text-sm ${full ? "bg-gray-50 text-gray-500" : selected.includes(s.id) ? "border-brand-300 bg-brand-50" : "hover:bg-gray-50"}`}>
<label className="flex items-center gap-2 flex-1 min-w-0">
<input type="checkbox" disabled={full && !selected.includes(s.id)} checked={selected.includes(s.id)} onChange={() => toggle(s.id)} />
<span className="font-medium">{name}</span>
@@ -24,9 +24,9 @@ export function SessionSchedule({ sessions, defaultLocation }: { sessions: Event
const isNext = next?.id === s.id;
const place = s.location && s.location !== defaultLocation ? s.location : null;
return (
<li key={s.id} className={`flex flex-wrap items-baseline gap-x-3 gap-y-0.5 rounded-lg px-3 py-2 text-sm ${isNext ? "bg-brand-50 border border-brand-200" : "border border-transparent"} ${past ? "text-gray-400" : "text-gray-700"}`}>
<span className={`font-medium ${cancelled ? "line-through text-gray-400" : ""}`}>{cancelled ? (s.label || "Session") : sessionLabel(s, sessions)}</span>
<span className={cancelled ? "line-through text-gray-400" : ""}>{formatSessionWhen(s)}</span>
<li key={s.id} className={`flex flex-wrap items-baseline gap-x-3 gap-y-0.5 rounded-lg px-3 py-2 text-sm ${isNext ? "bg-brand-50 border border-brand-200" : "border border-transparent"} ${past ? "text-gray-500" : "text-gray-700"}`}>
<span className={`font-medium ${cancelled ? "line-through text-gray-500" : ""}`}>{cancelled ? (s.label || "Session") : sessionLabel(s, sessions)}</span>
<span className={cancelled ? "line-through text-gray-500" : ""}>{formatSessionWhen(s)}</span>
{cancelled && <span className="text-xs font-medium text-amber-700">Cancelled</span>}
{isNext && <span className="text-xs font-medium text-brand-700">Next</span>}
{place && !cancelled && <span className="flex items-center gap-1 text-xs text-gray-500"><MapPin className="w-3 h-3" />{place}</span>}
@@ -6,6 +6,7 @@ import { apiFetch } from "@/lib/api";
import { useAuth } from "@/hooks/useAuth";
import { errorMessage } from "@/lib/utils";
import { useOnlinePayments } from "@/lib/onlinePayments";
import { ModalOverlay } from "@/components/shared/ModalOverlay";
type Sponsorship = { enabled: boolean; open?: boolean; spotPrice?: number | null; showProgress?: boolean; goalSpots?: number | null; spotsFunded?: number | null; sponsors?: number | null };
@@ -97,18 +98,18 @@ export function SponsorSpot({ eventId, eventTitle }: { eventId: string; eventTit
)}
{open && (
<div className="fixed inset-0 bg-black/40 flex items-center justify-center z-50" onClick={() => setOpen(false)}>
<form onSubmit={submit} className="bg-white rounded-xl shadow-lg max-w-md w-full mx-4 p-5 space-y-3 max-h-[90vh] overflow-y-auto" onClick={e => e.stopPropagation()}>
<ModalOverlay labelledBy="sponsor-title" onClose={() => setOpen(false)} closeOnBackdrop className="fixed inset-0 bg-black/40 flex items-center justify-center z-50">
<form onSubmit={submit} className="bg-white rounded-xl shadow-lg max-w-md w-full mx-4 p-5 space-y-3 max-h-[90vh] overflow-y-auto">
<div className="flex items-center justify-between">
<h3 className="text-lg font-semibold flex items-center gap-2"><HeartHandshake className="w-5 h-5 text-rose-600" /> Sponsor a spot</h3>
<h3 id="sponsor-title" className="text-lg font-semibold flex items-center gap-2"><HeartHandshake className="w-5 h-5 text-rose-600" aria-hidden="true" /> Sponsor a spot</h3>
<button type="button" onClick={() => setOpen(false)} aria-label="Close" className="p-1 rounded hover:bg-gray-100"><X className="w-4 h-4" /></button>
</div>
<p className="text-sm text-gray-600">Help someone come to {eventTitle} who couldn&apos;t otherwise afford it. Your gift goes into a sponsorship pool that the organisers use to cover places.</p>
{price ? (
<div className="flex gap-2 text-sm">
<button type="button" onClick={() => setMode("spots")} className={`flex-1 px-3 py-1.5 rounded-lg border ${mode === "spots" ? "bg-rose-600 text-white border-rose-600" : "hover:bg-gray-50"}`}>Whole spots</button>
<button type="button" onClick={() => setMode("amount")} className={`flex-1 px-3 py-1.5 rounded-lg border ${mode === "amount" ? "bg-rose-600 text-white border-rose-600" : "hover:bg-gray-50"}`}>Any amount</button>
<button type="button" onClick={() => setMode("spots")} aria-pressed={mode === "spots"} className={`flex-1 px-3 py-1.5 rounded-lg border ${mode === "spots" ? "bg-rose-600 text-white border-rose-600" : "hover:bg-gray-50"}`}>Whole spots</button>
<button type="button" onClick={() => setMode("amount")} aria-pressed={mode === "amount"} className={`flex-1 px-3 py-1.5 rounded-lg border ${mode === "amount" ? "bg-rose-600 text-white border-rose-600" : "hover:bg-gray-50"}`}>Any amount</button>
</div>
) : null}
{mode === "spots" && price ? (
@@ -118,32 +119,32 @@ export function SponsorSpot({ eventId, eventTitle }: { eventId: string; eventTit
</div>
) : (
<div>
<label className="block text-xs text-gray-600 mb-1">Amount (R)</label>
<input type="number" min={15} step="0.01" className={inputCls} value={amount} onChange={e => setAmount(e.target.value)} placeholder="e.g. 200" required />
<label htmlFor="sponsor-amount" className="block text-xs text-gray-600 mb-1">Amount (R)</label>
<input id="sponsor-amount" type="number" min={15} step="0.01" className={inputCls} value={amount} onChange={e => setAmount(e.target.value)} placeholder="e.g. 200" required />
<p className="text-xs text-gray-500 mt-1">Minimum R15.</p>
</div>
)}
{!loggedIn && (
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2">
<input className={inputCls} placeholder="Your name" value={guest.name} onChange={e => setGuest({ ...guest, name: e.target.value })} required />
<input type="email" className={inputCls} placeholder="Email (for your receipt)" value={guest.email} onChange={e => setGuest({ ...guest, email: e.target.value })} required />
<input className={inputCls} placeholder="Your name" aria-label="Your name" autoComplete="name" value={guest.name} onChange={e => setGuest({ ...guest, name: e.target.value })} required />
<input type="email" className={inputCls} placeholder="Email (for your receipt)" aria-label="Email (for your receipt)" autoComplete="email" value={guest.email} onChange={e => setGuest({ ...guest, email: e.target.value })} required />
</div>
)}
<label className="flex items-center gap-2 text-sm cursor-pointer">
<input type="checkbox" checked={anonymous} onChange={e => setAnonymous(e.target.checked)} /> Give anonymously
</label>
{!anonymous && (
<input className={inputCls} placeholder={`Name to show the organisers (e.g. "The Smith family")`} value={sponsorName} onChange={e => setSponsorName(e.target.value)} maxLength={100} />
<input className={inputCls} placeholder={`Name to show the organisers (e.g. "The Smith family")`} aria-label="Name to show the organisers" value={sponsorName} onChange={e => setSponsorName(e.target.value)} maxLength={100} />
)}
<textarea className={inputCls} rows={2} placeholder="A message for the organisers (optional)" value={message} onChange={e => setMessage(e.target.value)} maxLength={300} />
<textarea className={inputCls} rows={2} placeholder="A message for the organisers (optional)" aria-label="A message for the organisers (optional)" value={message} onChange={e => setMessage(e.target.value)} maxLength={300} />
<p className="text-xs text-gray-500">You&apos;ll get a receipt by email. We never share who is helped by sponsorships.</p>
{error && <div className="p-2 rounded bg-red-50 text-red-800 text-sm">{error}</div>}
{error && <div role="alert" className="p-2 rounded bg-red-50 text-red-800 text-sm">{error}</div>}
<button type="submit" disabled={busy || !(total >= 15)} className="w-full px-4 py-2 rounded-lg bg-rose-600 text-white hover:bg-rose-700 disabled:opacity-50 font-medium">
{busy ? "Opening payment…" : `Pay ${total > 0 ? rand(total) : ""} securely`}
</button>
</form>
</div>
</ModalOverlay>
)}
</div>
);
@@ -0,0 +1,27 @@
"use client";
/**
* "Skip to main content" — the first thing a keyboard user reaches on every page. Hidden
* until focused. Pages put their content in a <main> of their own, so the link finds it
* when used rather than relying on a fixed id.
*/
export function SkipLink() {
const skip = (e: React.MouseEvent<HTMLAnchorElement>) => {
const main = document.querySelector("main");
if (!main) return;
e.preventDefault();
if (!main.hasAttribute("tabindex")) main.setAttribute("tabindex", "-1");
main.focus();
main.scrollIntoView();
};
return (
<a
href="#main"
onClick={skip}
className="sr-only focus:not-sr-only focus:fixed focus:top-2 focus:left-2 focus:z-[100] focus:rounded-md focus:bg-white focus:px-4 focus:py-2 focus:text-sm focus:font-medium focus:text-gray-900 focus:shadow-lg"
>
Skip to main content
</a>
);
}
@@ -172,7 +172,7 @@ export function AttendeeNamesEditor({
)}
{consent && (
<div className="mt-2">
<label className="block text-xs text-gray-600 mb-1">Date of birth</label>
<p aria-hidden="true" className="block text-xs text-gray-600 mb-1">Date of birth</p>
<input type="date" className={`${inputCls} sm:w-48`} value={e.dateOfBirth || ""} max={new Date().toISOString().slice(0, 10)} onChange={ev => set(s.key, "dateOfBirth", ev.target.value)} aria-label={`${s.label} date of birth`} />
{isMinorOn(e.dateOfBirth, consentEventStart) && (
<div className="mt-2 rounded-lg bg-amber-50 border border-amber-200 p-2">
@@ -115,7 +115,7 @@ export function CouponCodeField({
return (
<div>
{!compact && <label className="block text-sm font-medium text-gray-700 mb-1">Discount code</label>}
{!compact && <p aria-hidden="true" className="block text-sm font-medium text-gray-700 mb-1">Discount code</p>}
<div className="flex gap-2">
<input
value={code}
@@ -0,0 +1,83 @@
"use client";
import { useEffect, useRef, useState } from "react";
const FOCUSABLE =
'a[href], button:not([disabled]), input:not([disabled]):not([type="hidden"]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
/**
* The dark backdrop for the app's own popups, with what a screen reader and keyboard need:
* announced as a dialog (named by `labelledBy`, the id of its heading), focus moved inside
* when it opens and kept there with Tab, Escape closes it (when `onClose` is given), and
* focus goes back to whatever opened it afterwards.
*/
export function ModalOverlay({
labelledBy,
onClose,
closeOnBackdrop = false,
className = "fixed inset-0 z-50 flex items-center justify-center bg-black/40",
children,
}: {
labelledBy: string;
onClose?: () => void;
/** Also close on a click on the dark backdrop (outside the popup). */
closeOnBackdrop?: boolean;
className?: string;
children: React.ReactNode;
}) {
const ref = useRef<HTMLDivElement>(null);
const closeRef = useRef(onClose);
closeRef.current = onClose;
// Taken while rendering: an autoFocus inside moves focus before the effect runs.
const [opener] = useState(() => (typeof document === "undefined" ? null : (document.activeElement as HTMLElement | null)));
useEffect(() => {
const box = ref.current;
// Respect an autoFocus inside; otherwise focus the first control, or the dialog itself.
if (box && !box.contains(document.activeElement)) {
(box.querySelector<HTMLElement>(FOCUSABLE) ?? box).focus();
}
const onKey = (e: KeyboardEvent) => {
if (e.key === "Escape" && closeRef.current) {
e.stopPropagation();
closeRef.current();
return;
}
if (e.key !== "Tab" || !box) return;
const items = Array.from(box.querySelectorAll<HTMLElement>(FOCUSABLE)).filter((el) => el.offsetParent !== null);
if (items.length === 0) {
e.preventDefault();
return;
}
const first = items[0];
const last = items[items.length - 1];
if (e.shiftKey && (document.activeElement === first || !box.contains(document.activeElement))) {
e.preventDefault();
last.focus();
} else if (!e.shiftKey && (document.activeElement === last || !box.contains(document.activeElement))) {
e.preventDefault();
first.focus();
}
};
document.addEventListener("keydown", onKey);
return () => {
document.removeEventListener("keydown", onKey);
if (opener && document.contains(opener)) opener.focus();
};
}, [opener]);
return (
<div
ref={ref}
role="dialog"
aria-modal="true"
aria-labelledby={labelledBy}
tabIndex={-1}
className={className}
onClick={closeOnBackdrop && onClose ? (e) => { if (e.target === e.currentTarget) onClose(); } : undefined}
>
{children}
</div>
);
}
@@ -5,6 +5,7 @@ import { ArrowRightLeft } from "lucide-react";
import { apiFetch } from "@/lib/api";
import { isMinorOn } from "@/components/shared/AttendeeNamesEditor";
import { errorMessage } from "@/lib/utils";
import { ModalOverlay } from "@/components/shared/ModalOverlay";
type TransferTicket = { id: string; isUsed?: boolean; quantity?: number; usages?: unknown[] };
type TransferEvent = {
@@ -60,11 +61,11 @@ export function TransferTicketModal({ ticket, event, token, onClose, onDone }: {
const input = "w-full border rounded-lg px-3 py-2 text-sm";
return (
<div className="fixed inset-0 bg-black/40 flex items-center justify-center z-50" onClick={onClose}>
<form onSubmit={submit} className="bg-white rounded-xl shadow-lg max-w-md w-full mx-4 p-5 space-y-3 max-h-[90vh] overflow-y-auto" onClick={e => e.stopPropagation()}>
<ModalOverlay labelledBy="transfer-title" onClose={onClose} closeOnBackdrop className="fixed inset-0 bg-black/40 flex items-center justify-center z-50">
<form onSubmit={submit} className="bg-white rounded-xl shadow-lg max-w-md w-full mx-4 p-5 space-y-3 max-h-[90vh] overflow-y-auto">
<div className="flex items-center gap-2">
<ArrowRightLeft className="w-5 h-5 text-brand-600" />
<h3 className="text-lg font-semibold">Transfer ticket</h3>
<ArrowRightLeft className="w-5 h-5 text-brand-600" aria-hidden="true" />
<h3 id="transfer-title" className="text-lg font-semibold">Transfer ticket</h3>
</div>
<p className="text-sm text-gray-600">
We&apos;ll send them a link to accept the ticket. Nothing changes until they accept — then{" "}
@@ -74,23 +75,23 @@ export function TransferTicketModal({ ticket, event, token, onClose, onDone }: {
{" "}The booking and payment stay with the person who booked.
</p>
<div>
<label className="block text-xs text-gray-600 mb-1">New holder&apos;s name</label>
<input className={input} value={f.name} onChange={set("name")} required maxLength={100} />
<label htmlFor="transfer-new-holders-name" className="block text-xs text-gray-600 mb-1">New holder&apos;s name</label>
<input id="transfer-new-holders-name" className={input} value={f.name} onChange={set("name")} required maxLength={100} />
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2">
<div>
<label className="block text-xs text-gray-600 mb-1">Email</label>
<input type="email" className={input} value={f.email} onChange={set("email")} />
<label htmlFor="transfer-email" className="block text-xs text-gray-600 mb-1">Email</label>
<input id="transfer-email" type="email" className={input} value={f.email} onChange={set("email")} />
</div>
<div>
<label className="block text-xs text-gray-600 mb-1">Phone (WhatsApp)</label>
<input type="tel" className={input} value={f.phone} onChange={set("phone")} />
<label htmlFor="transfer-phone" className="block text-xs text-gray-600 mb-1">Phone (WhatsApp)</label>
<input id="transfer-phone" type="tel" className={input} value={f.phone} onChange={set("phone")} />
</div>
</div>
{event?.collectGender && (
<div>
<label className="block text-xs text-gray-600 mb-1">Gender</label>
<select className={input} value={f.gender} onChange={set("gender")} required>
<label htmlFor="transfer-gender" className="block text-xs text-gray-600 mb-1">Gender</label>
<select id="transfer-gender" className={input} value={f.gender} onChange={set("gender")} required>
<option value="">Choose…</option>
<option value="male">Male</option>
<option value="female">Female</option>
@@ -101,22 +102,22 @@ export function TransferTicketModal({ ticket, event, token, onClose, onDone }: {
{youth && (
<div className="space-y-2 border-t pt-3">
<div>
<label className="block text-xs text-gray-600 mb-1">Date of birth</label>
<input type="date" className={input} value={f.dateOfBirth} onChange={set("dateOfBirth")} required />
<label htmlFor="transfer-date-of-birth" className="block text-xs text-gray-600 mb-1">Date of birth</label>
<input id="transfer-date-of-birth" type="date" className={input} value={f.dateOfBirth} onChange={set("dateOfBirth")} required />
</div>
{minor && (
<>
<p className="text-xs text-amber-800 bg-amber-50 rounded p-2">They&apos;re under 18, so a parent or guardian will be asked for consent before they can check in.</p>
<input className={input} placeholder="Parent or guardian's name" value={f.parentName} onChange={set("parentName")} required />
<input className={input} placeholder="Parent or guardian's name" aria-label="Parent or guardian's name" value={f.parentName} onChange={set("parentName")} required />
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2">
<input type="email" className={input} placeholder="Parent's email" value={f.parentEmail} onChange={set("parentEmail")} required />
<input type="tel" className={input} placeholder="Parent's phone" value={f.parentPhone} onChange={set("parentPhone")} required />
<input type="email" className={input} placeholder="Parent's email" aria-label="Parent's email" value={f.parentEmail} onChange={set("parentEmail")} required />
<input type="tel" className={input} placeholder="Parent's phone" aria-label="Parent's phone" value={f.parentPhone} onChange={set("parentPhone")} required />
</div>
</>
)}
</div>
)}
{error && <div className="p-2 rounded bg-red-50 text-red-800 text-sm">{error}</div>}
{error && <div role="alert" className="p-2 rounded bg-red-50 text-red-800 text-sm">{error}</div>}
<div className="flex justify-end gap-2 pt-1">
<button type="button" onClick={onClose} className="px-3 py-1.5 text-sm rounded bg-gray-100 hover:bg-gray-200">Cancel</button>
<button type="submit" disabled={busy || !f.name.trim() || (!f.email.trim() && !f.phone.trim())} className="px-3 py-1.5 text-sm rounded bg-brand-600 text-white hover:bg-brand-700 disabled:opacity-50">
@@ -124,6 +125,6 @@ export function TransferTicketModal({ ticket, event, token, onClose, onDone }: {
</button>
</div>
</form>
</div>
</ModalOverlay>
);
}