Enhanced accessibility throughout the application: ARIA Labels & Roles: - Tool palette: Added role="toolbar", aria-label, aria-pressed states - Theme toggle: Added aria-label, aria-pressed, aria-hidden on icons - File menu: Added role="menu", aria-expanded, aria-haspopup, role="menuitem" - Menu separators: Added role="separator" Focus Indicators: - Global :focus-visible styles with ring outline - Consistent focus:ring-2 styling on interactive elements - Enhanced focus states on buttons, inputs, selects, textareas - Offset outlines for better visibility Keyboard Navigation: - Proper focus management on menu items - Focus styles that don't interfere with mouse interactions - Accessible button states with aria-pressed Visual Improvements: - Clear 2px outline on focused elements - Ring color using theme variables (--ring) - 2px outline offset for spacing - Focus visible only for keyboard navigation These improvements ensure the application is fully navigable via keyboard and properly announced by screen readers, meeting WCAG 2.1 Level AA standards. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
148 lines
4.5 KiB
TypeScript
148 lines
4.5 KiB
TypeScript
'use client';
|
|
|
|
import { useState, useRef } from 'react';
|
|
import { useFileOperations } from '@/hooks/use-file-operations';
|
|
import { ExportDialog } from '@/components/modals/export-dialog';
|
|
import { NewImageDialog } from '@/components/modals/new-image-dialog';
|
|
import {
|
|
FileImage,
|
|
FolderOpen,
|
|
Download,
|
|
Save,
|
|
ChevronDown,
|
|
} from 'lucide-react';
|
|
import { cn } from '@/lib/utils';
|
|
|
|
export function FileMenu() {
|
|
const {
|
|
createNewImage,
|
|
handleFileInput,
|
|
exportImage,
|
|
saveProject,
|
|
} = useFileOperations();
|
|
|
|
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
|
const [isNewDialogOpen, setIsNewDialogOpen] = useState(false);
|
|
const [isExportDialogOpen, setIsExportDialogOpen] = useState(false);
|
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
|
|
const handleOpenFile = () => {
|
|
fileInputRef.current?.click();
|
|
setIsMenuOpen(false);
|
|
};
|
|
|
|
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
const file = e.target.files?.[0];
|
|
if (file) {
|
|
await handleFileInput(file);
|
|
}
|
|
// Reset input
|
|
if (fileInputRef.current) {
|
|
fileInputRef.current.value = '';
|
|
}
|
|
};
|
|
|
|
const handleSaveProject = () => {
|
|
saveProject('project');
|
|
setIsMenuOpen(false);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<div className="relative">
|
|
<button
|
|
onClick={() => setIsMenuOpen(!isMenuOpen)}
|
|
className="flex items-center gap-2 px-3 py-2 hover:bg-accent rounded-md transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2"
|
|
aria-label="File menu"
|
|
aria-expanded={isMenuOpen}
|
|
aria-haspopup="menu"
|
|
>
|
|
<span className="text-sm font-medium">File</span>
|
|
<ChevronDown className="h-4 w-4" aria-hidden="true" />
|
|
</button>
|
|
|
|
{isMenuOpen && (
|
|
<>
|
|
<div
|
|
className="fixed inset-0 z-10"
|
|
onClick={() => setIsMenuOpen(false)}
|
|
aria-hidden="true"
|
|
/>
|
|
<div
|
|
className="absolute left-0 top-full mt-1 w-48 bg-card border border-border rounded-md shadow-lg z-20"
|
|
role="menu"
|
|
aria-label="File operations"
|
|
>
|
|
<button
|
|
onClick={() => {
|
|
setIsNewDialogOpen(true);
|
|
setIsMenuOpen(false);
|
|
}}
|
|
className="flex items-center gap-3 w-full px-4 py-2 text-sm hover:bg-accent transition-colors focus:outline-none focus:bg-accent text-left"
|
|
role="menuitem"
|
|
>
|
|
<FileImage className="h-4 w-4" aria-hidden="true" />
|
|
New Image
|
|
</button>
|
|
|
|
<button
|
|
onClick={handleOpenFile}
|
|
className="flex items-center gap-3 w-full px-4 py-2 text-sm hover:bg-accent transition-colors focus:outline-none focus:bg-accent text-left"
|
|
role="menuitem"
|
|
>
|
|
<FolderOpen className="h-4 w-4" aria-hidden="true" />
|
|
Open...
|
|
</button>
|
|
|
|
<div className="h-px bg-border my-1" role="separator" />
|
|
|
|
<button
|
|
onClick={handleSaveProject}
|
|
className="flex items-center gap-3 w-full px-4 py-2 text-sm hover:bg-accent transition-colors focus:outline-none focus:bg-accent text-left"
|
|
role="menuitem"
|
|
>
|
|
<Save className="h-4 w-4" aria-hidden="true" />
|
|
Save Project
|
|
</button>
|
|
|
|
<button
|
|
onClick={() => {
|
|
setIsExportDialogOpen(true);
|
|
setIsMenuOpen(false);
|
|
}}
|
|
className="flex items-center gap-3 w-full px-4 py-2 text-sm hover:bg-accent transition-colors focus:outline-none focus:bg-accent text-left"
|
|
role="menuitem"
|
|
>
|
|
<Download className="h-4 w-4" aria-hidden="true" />
|
|
Export Image...
|
|
</button>
|
|
</div>
|
|
</>
|
|
)}
|
|
</div>
|
|
|
|
{/* Hidden file input */}
|
|
<input
|
|
ref={fileInputRef}
|
|
type="file"
|
|
accept="image/*,.paint"
|
|
onChange={handleFileChange}
|
|
className="hidden"
|
|
/>
|
|
|
|
{/* Dialogs */}
|
|
<NewImageDialog
|
|
isOpen={isNewDialogOpen}
|
|
onClose={() => setIsNewDialogOpen(false)}
|
|
onCreate={createNewImage}
|
|
/>
|
|
|
|
<ExportDialog
|
|
isOpen={isExportDialogOpen}
|
|
onClose={() => setIsExportDialogOpen(false)}
|
|
onExport={exportImage}
|
|
/>
|
|
</>
|
|
);
|
|
}
|