Skip to content

Commit 5dc9bcd

Browse files
committed
delegate basic events to radix, keep modifier logic
1 parent 689e57f commit 5dc9bcd

File tree

2 files changed

+17
-27
lines changed

2 files changed

+17
-27
lines changed

src/components/imageLightbox/index.tsx

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,17 @@ export function ImageLightbox({
7171
e.preventDefault();
7272
e.stopPropagation();
7373
openInNewTab();
74-
return;
7574
}
76-
// Regular click opens lightbox - let it bubble to Dialog.Trigger
75+
// Regular click is handled by Dialog.Trigger
7776
};
7877

7978
const handleKeyDown = (e: React.KeyboardEvent) => {
80-
if (e.key === 'Enter' || e.key === ' ') {
81-
if (e.ctrlKey || e.metaKey) {
82-
e.preventDefault();
83-
e.stopPropagation();
84-
openInNewTab();
85-
return;
86-
}
87-
// Regular Enter/Space should open lightbox
79+
// Ctrl/Cmd+Enter/Space opens in new tab
80+
// Regular Enter/Space is handled by Dialog.Trigger
81+
if ((e.key === 'Enter' || e.key === ' ') && (e.ctrlKey || e.metaKey)) {
8882
e.preventDefault();
89-
setOpen(true);
83+
e.stopPropagation();
84+
openInNewTab();
9085
}
9186
};
9287

@@ -133,18 +128,14 @@ export function ImageLightbox({
133128

134129
return (
135130
<Lightbox.Root open={open} onOpenChange={setOpen} content={renderImage(false)}>
136-
<Lightbox.Trigger asChild>
137-
<div
138-
onClick={handleClick}
139-
onAuxClick={handleClick}
140-
onKeyDown={handleKeyDown}
141-
className="cursor-pointer border-none bg-transparent p-0 block w-full no-underline"
142-
aria-label={`View image: ${alt}`}
143-
role="button"
144-
tabIndex={0}
145-
>
146-
{renderImage()}
147-
</div>
131+
<Lightbox.Trigger
132+
onClick={handleClick}
133+
onAuxClick={handleClick}
134+
onKeyDown={handleKeyDown}
135+
className="cursor-pointer border-none bg-transparent p-0 block w-full no-underline"
136+
aria-label={`View image: ${alt}`}
137+
>
138+
{renderImage()}
148139
</Lightbox.Trigger>
149140
</Lightbox.Root>
150141
);

src/components/lightbox/index.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ interface LightboxProps {
3939
open?: boolean;
4040
}
4141

42-
interface LightboxTriggerProps {
42+
interface LightboxTriggerProps extends React.ComponentProps<typeof Dialog.Trigger> {
4343
children: React.ReactNode;
44-
asChild?: boolean;
4544
}
4645

4746
interface LightboxCloseProps {
@@ -83,8 +82,8 @@ function LightboxRoot({
8382
}
8483

8584
// Trigger component
86-
function LightboxTrigger({children, asChild = false}: LightboxTriggerProps) {
87-
return <Dialog.Trigger asChild={asChild}>{children}</Dialog.Trigger>;
85+
function LightboxTrigger({children, ...props}: LightboxTriggerProps) {
86+
return <Dialog.Trigger {...props}>{children}</Dialog.Trigger>;
8887
}
8988

9089
// Close button component

0 commit comments

Comments
 (0)