File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -38,12 +38,34 @@ export function ImageLightbox({
38
38
setOpen ( true ) ;
39
39
} ;
40
40
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
+
41
59
return (
42
60
< Dialog . Root open = { open } onOpenChange = { setOpen } >
43
61
{ /* Custom trigger that handles modifier keys properly */ }
44
62
< div
63
+ role = "button"
64
+ tabIndex = { 0 }
45
65
className = "cursor-pointer border-none bg-transparent p-0 block w-full no-underline"
46
66
onClick = { handleClick }
67
+ onKeyDown = { handleKeyDown }
68
+ aria-label = { `View image: ${ alt } ` }
47
69
>
48
70
{ children }
49
71
</ div >
You can’t perform that action at this time.
0 commit comments