Files
immich-folio/components/PasswordGate.tsx
Ralksta 6a45dc3657 Add aria-label to input fields for better accessibility (#39)
Added aria-labels to the password input in `components/PasswordGate.tsx` and the grid columns/gap inputs in `components/DevToolbar.tsx` to provide clear semantic meaning for screen readers.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
2026-03-22 09:57:29 +01:00

73 lines
1.9 KiB
TypeScript

'use client';
/**
* Password gate — shown when accessing a protected album/subpage.
* Submits to /api/auth and refreshes on success.
*/
import { useState } from 'react';
import styles from './PasswordGate.module.css';
interface PasswordGateProps {
slug: string;
title: string;
}
export default function PasswordGate({ slug, title }: PasswordGateProps) {
const [password, setPassword] = useState('');
const [error, setError] = useState('');
const [loading, setLoading] = useState(false);
async function handleSubmit(e: React.FormEvent) {
e.preventDefault();
setError('');
setLoading(true);
try {
const res = await fetch('/api/auth', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ slug, password }),
});
if (res.ok) {
window.location.reload();
} else {
setError('Wrong password');
setPassword('');
}
} catch {
setError('Something went wrong');
} finally {
setLoading(false);
}
}
return (
<div className={styles.gate}>
<div className={styles.card}>
<h2 className={styles.title}>{title}</h2>
<p className={styles.subtitle}>This gallery is password-protected.</p>
<form onSubmit={handleSubmit} className={styles.form}>
<input
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
placeholder="Enter password"
aria-label="Enter password"
className={styles.input}
autoFocus
required
/>
<button type="submit" className={styles.button} disabled={loading}>
{loading ? 'Verifying…' : 'Enter'}
</button>
</form>
{error && <p className={styles.error}>{error}</p>}
</div>
</div>
);
}