Skip to content

Commit 7b781f4

Browse files
committed
add basic a11y
1 parent 19db25b commit 7b781f4

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/components/imageLightbox.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,34 @@ export function ImageLightbox({
3838
setOpen(true);
3939
};
4040

41+
const handleKeyDown = (e: React.KeyboardEvent) => {
42+
// Handle Enter and Space keys
43+
if (e.key === 'Enter' || e.key === ' ') {
44+
e.preventDefault();
45+
// If Ctrl/Cmd+key, open image in new tab
46+
if (e.ctrlKey || e.metaKey) {
47+
const url = src.startsWith('http') ? src : imgPath;
48+
const newWindow = window.open(url, '_blank');
49+
if (newWindow) {
50+
newWindow.opener = null; // Security: prevent opener access
51+
}
52+
return;
53+
}
54+
// Normal key press - open lightbox
55+
setOpen(true);
56+
}
57+
};
58+
4159
return (
4260
<Dialog.Root open={open} onOpenChange={setOpen}>
4361
{/* Custom trigger that handles modifier keys properly */}
4462
<div
63+
role="button"
64+
tabIndex={0}
4565
className="cursor-pointer border-none bg-transparent p-0 block w-full no-underline"
4666
onClick={handleClick}
67+
onKeyDown={handleKeyDown}
68+
aria-label={`View image: ${alt}`}
4769
>
4870
{children}
4971
</div>

0 commit comments

Comments
 (0)