Implemented comprehensive form accessibility improvements across all critical forms:
**Accessibility Attributes Added:**
- aria-required="true" on all required form fields
- aria-invalid on fields with validation errors
- aria-describedby linking error messages to inputs
- Unique id attributes on FormHelperText for error association
- role="alert" on error messages for screen reader announcements
- labelId on Select components for proper label association
- noValidate on forms to use custom validation
**Forms Updated:**
1. Login Form (app/(auth)/login/page.tsx)
- Email and password fields with full ARIA support
- Error message association with aria-describedby
2. Registration Form (app/(auth)/register/page.tsx)
- All text fields: name, email, password, DOB, parental email
- Checkbox fields: Terms, Privacy, COPPA consent
- Conditional required fields for minors
3. Child Dialog (components/children/ChildDialog.tsx)
- Name, birthdate, gender fields
- Dynamic aria-invalid based on validation state
4. Tracking Forms:
- Feeding form (app/track/feeding/page.tsx)
- Child selector, side selector, bottle type
- Food description with required validation
- Sleep form (app/track/sleep/page.tsx)
- Child selector, start/end time fields
- Quality and location selectors
**WCAG 2.1 Compliance:**
- ✅ 3.3.2 Labels or Instructions (AA)
- ✅ 4.1.3 Status Messages (AA)
- ✅ 1.3.1 Info and Relationships (A)
- ✅ 3.3.1 Error Identification (A)
**Documentation:**
- Updated REMAINING_FEATURES.md
- Marked Form Accessibility Enhancement as complete
- Status: 79 features completed (57%)
🎉 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
186 lines
5.0 KiB
TypeScript
186 lines
5.0 KiB
TypeScript
'use client';
|
|
|
|
import { useState, useEffect } from 'react';
|
|
import {
|
|
Dialog,
|
|
DialogTitle,
|
|
DialogContent,
|
|
DialogActions,
|
|
Button,
|
|
TextField,
|
|
MenuItem,
|
|
Box,
|
|
Alert,
|
|
} from '@mui/material';
|
|
import { Child, CreateChildData } from '@/lib/api/children';
|
|
import { useTranslation } from '@/hooks/useTranslation';
|
|
import { PhotoUpload } from '@/components/common/PhotoUpload';
|
|
|
|
interface ChildDialogProps {
|
|
open: boolean;
|
|
onClose: () => void;
|
|
onSubmit: (data: CreateChildData) => Promise<void>;
|
|
child?: Child | null;
|
|
isLoading?: boolean;
|
|
}
|
|
|
|
export function ChildDialog({ open, onClose, onSubmit, child, isLoading = false }: ChildDialogProps) {
|
|
const { t } = useTranslation('children');
|
|
const [formData, setFormData] = useState<CreateChildData>({
|
|
name: '',
|
|
birthDate: '',
|
|
gender: 'male',
|
|
photoUrl: '',
|
|
photoAlt: '',
|
|
});
|
|
const [error, setError] = useState<string>('');
|
|
|
|
useEffect(() => {
|
|
if (child) {
|
|
setFormData({
|
|
name: child.name,
|
|
birthDate: child.birthDate.split('T')[0], // Convert to YYYY-MM-DD format
|
|
gender: child.gender,
|
|
photoUrl: child.photoUrl || '',
|
|
photoAlt: child.photoAlt || '',
|
|
});
|
|
} else {
|
|
setFormData({
|
|
name: '',
|
|
birthDate: '',
|
|
gender: 'male',
|
|
photoUrl: '',
|
|
photoAlt: '',
|
|
});
|
|
}
|
|
setError('');
|
|
}, [child, open]);
|
|
|
|
const handleChange = (field: keyof CreateChildData) => (
|
|
e: React.ChangeEvent<HTMLInputElement>
|
|
) => {
|
|
setFormData({ ...formData, [field]: e.target.value });
|
|
};
|
|
|
|
const handleSubmit = async () => {
|
|
setError('');
|
|
|
|
// Validation
|
|
if (!formData.name.trim()) {
|
|
setError(t('dialog.validation.nameRequired'));
|
|
return;
|
|
}
|
|
if (!formData.birthDate) {
|
|
setError(t('dialog.validation.birthDateRequired'));
|
|
return;
|
|
}
|
|
|
|
// Check if birth date is in the future
|
|
const selectedDate = new Date(formData.birthDate);
|
|
const today = new Date();
|
|
today.setHours(0, 0, 0, 0);
|
|
if (selectedDate > today) {
|
|
setError(t('dialog.validation.birthDateFuture'));
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await onSubmit(formData);
|
|
onClose();
|
|
} catch (err: any) {
|
|
setError(err.message || t('errors.saveFailed'));
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Dialog
|
|
open={open}
|
|
onClose={onClose}
|
|
maxWidth="sm"
|
|
fullWidth
|
|
aria-labelledby="child-dialog-title"
|
|
aria-describedby="child-dialog-description"
|
|
>
|
|
<DialogTitle id="child-dialog-title">{child ? t('editChild') : t('addChild')}</DialogTitle>
|
|
<DialogContent>
|
|
<Box
|
|
id="child-dialog-description"
|
|
sx={{ pt: 2, display: 'flex', flexDirection: 'column', gap: 2 }}
|
|
>
|
|
{error && (
|
|
<Alert severity="error" onClose={() => setError('')} role="alert">
|
|
{error}
|
|
</Alert>
|
|
)}
|
|
|
|
<TextField
|
|
label={t('dialog.name')}
|
|
value={formData.name}
|
|
onChange={handleChange('name')}
|
|
fullWidth
|
|
required
|
|
autoFocus
|
|
disabled={isLoading}
|
|
inputProps={{
|
|
'aria-required': 'true',
|
|
'aria-invalid': !formData.name.trim() && error ? 'true' : 'false',
|
|
}}
|
|
/>
|
|
|
|
<TextField
|
|
label={t('dialog.birthDate')}
|
|
type="date"
|
|
value={formData.birthDate}
|
|
onChange={handleChange('birthDate')}
|
|
fullWidth
|
|
required
|
|
InputLabelProps={{
|
|
shrink: true,
|
|
}}
|
|
disabled={isLoading}
|
|
inputProps={{
|
|
'aria-required': 'true',
|
|
'aria-invalid': !formData.birthDate && error ? 'true' : 'false',
|
|
}}
|
|
/>
|
|
|
|
<TextField
|
|
label={t('dialog.gender')}
|
|
value={formData.gender}
|
|
onChange={handleChange('gender')}
|
|
fullWidth
|
|
required
|
|
select
|
|
disabled={isLoading}
|
|
inputProps={{
|
|
'aria-required': 'true',
|
|
}}
|
|
>
|
|
<MenuItem value="male">{t('gender.male')}</MenuItem>
|
|
<MenuItem value="female">{t('gender.female')}</MenuItem>
|
|
<MenuItem value="other">{t('gender.other')}</MenuItem>
|
|
</TextField>
|
|
|
|
<PhotoUpload
|
|
label={t('dialog.photoUrl')}
|
|
value={formData.photoUrl || ''}
|
|
onChange={(url) => setFormData({ ...formData, photoUrl: url })}
|
|
altText={formData.photoAlt || ''}
|
|
onAltTextChange={(altText) => setFormData({ ...formData, photoAlt: altText })}
|
|
disabled={isLoading}
|
|
size={80}
|
|
/>
|
|
</Box>
|
|
</DialogContent>
|
|
<DialogActions>
|
|
<Button onClick={onClose} disabled={isLoading}>
|
|
{t('dialog.cancel')}
|
|
</Button>
|
|
<Button onClick={handleSubmit} variant="contained" disabled={isLoading}>
|
|
{isLoading ? t('dialog.saving') : child ? t('dialog.update') : t('dialog.add')}
|
|
</Button>
|
|
</DialogActions>
|
|
</Dialog>
|
|
);
|
|
}
|