Skip to content

Commit 689e57f

Browse files
committed
bugbot smash
1 parent 4be0b7e commit 689e57f

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

src/components/imageLightbox/index.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ interface ImageLightboxProps
1818
width?: number;
1919
}
2020

21-
const getImageUrl = (src: string, imgPath: string): string =>
22-
isExternalImage(src) ? src : imgPath;
21+
const getImageUrl = (src: string, imgPath: string): string => {
22+
if (isExternalImage(src)) {
23+
// Normalize protocol-relative URLs to use https:
24+
return src.startsWith('//') ? `https:${src}` : src;
25+
}
26+
return imgPath;
27+
};
2328

2429
type ValidDimensions = {
2530
height: number;
@@ -57,25 +62,32 @@ export function ImageLightbox({
5762
!!dimensions && (!isExternalImage(src) || isAllowedRemoteImage(src));
5863

5964
const openInNewTab = () => {
60-
window.open(getImageUrl(src, imgPath), '_blank');
65+
window.open(getImageUrl(src, imgPath), '_blank', 'noopener,noreferrer');
6166
};
6267

6368
const handleClick = (e: React.MouseEvent) => {
6469
// Middle-click or Ctrl/Cmd+click opens in new tab
6570
if (e.button === 1 || e.ctrlKey || e.metaKey) {
6671
e.preventDefault();
72+
e.stopPropagation();
6773
openInNewTab();
6874
return;
6975
}
70-
// Regular click falls through to Dialog.Trigger
76+
// Regular click opens lightbox - let it bubble to Dialog.Trigger
7177
};
7278

7379
const handleKeyDown = (e: React.KeyboardEvent) => {
74-
if ((e.key === 'Enter' || e.key === ' ') && (e.ctrlKey || e.metaKey)) {
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
7588
e.preventDefault();
76-
openInNewTab();
89+
setOpen(true);
7790
}
78-
// Regular Enter/Space falls through to Dialog.Trigger
7991
};
8092

8193
// Filter out props that are incompatible with Next.js Image component

src/components/lightbox/index.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
/**
2-
* Reusable Lightbox component built on top of Radix UI Dialog
2+
* Reusable Lightbox component built on top of Radix UI Dialog.
3+
* Provides a modal overlay for displaying images or other content.
34
*
45
* @example
5-
* // Simple usage with children as trigger
6+
* // Basic usage - you must provide Lightbox.Trigger as children
67
* <Lightbox.Root content={<img src="large.jpg" />}>
7-
* <img src="thumbnail.jpg" alt="Click to expand" />
8+
* <Lightbox.Trigger asChild>
9+
* <img src="thumbnail.jpg" alt="Click to expand" />
10+
* </Lightbox.Trigger>
811
* </Lightbox.Root>
912
*
1013
* @example
11-
* // Advanced usage with Lightbox.Trigger and controlled state
14+
* // Controlled state with custom trigger
1215
* const [open, setOpen] = useState(false);
1316
*
1417
* <Lightbox.Root open={open} onOpenChange={setOpen} content={<MyLargeContent />}>
@@ -34,7 +37,6 @@ interface LightboxProps {
3437
closeButton?: boolean;
3538
onOpenChange?: (open: boolean) => void;
3639
open?: boolean;
37-
trigger?: React.ReactNode;
3840
}
3941

4042
interface LightboxTriggerProps {
@@ -51,7 +53,6 @@ interface LightboxCloseProps {
5153
function LightboxRoot({
5254
children,
5355
content,
54-
trigger,
5556
onOpenChange,
5657
open: controlledOpen,
5758
closeButton = true,
@@ -63,7 +64,7 @@ function LightboxRoot({
6364

6465
return (
6566
<Dialog.Root open={open} onOpenChange={setOpen}>
66-
{trigger || (children && <Dialog.Trigger asChild>{children}</Dialog.Trigger>)}
67+
{children}
6768

6869
<Dialog.Portal>
6970
<Dialog.Overlay className={styles.lightboxOverlay} />

0 commit comments

Comments
 (0)