Disable zoom F key listener on root

This commit is contained in:
Sam Becker 2025-01-26 15:10:22 -06:00
parent 8ff534a65b
commit 637e5cd2d3
4 changed files with 48 additions and 31 deletions

View File

@ -9,6 +9,7 @@ const EVENT_KEYDOWN = 'keydown';
export default function useImageZoomControls( export default function useImageZoomControls(
imageRef: RefObject<HTMLDivElement | null>, imageRef: RefObject<HTMLDivElement | null>,
isEnabled?: boolean, isEnabled?: boolean,
shouldExpandOnFKeydown?: boolean,
) { ) {
const viewerRef = useRef<Viewer | null>(null); const viewerRef = useRef<Viewer | null>(null);
@ -67,10 +68,14 @@ export default function useImageZoomControls(
// On 'F' keydown, toggle fullscreen // On 'F' keydown, toggle fullscreen
const handleKeyDown = useCallback((e: KeyboardEvent) => { const handleKeyDown = useCallback((e: KeyboardEvent) => {
if (!isCommandKOpen && e.key.toUpperCase() === 'F') { if (
shouldExpandOnFKeydown &&
!isCommandKOpen &&
e.key.toUpperCase() === 'F'
) {
viewerRef.current?.show(); viewerRef.current?.show();
} }
}, [isCommandKOpen]); }, [shouldExpandOnFKeydown, isCommandKOpen]);
useEffect(() => { useEffect(() => {
document.addEventListener(EVENT_KEYDOWN, handleKeyDown); document.addEventListener(EVENT_KEYDOWN, handleKeyDown);
return () => { return () => {

View File

@ -53,6 +53,7 @@ export default function PhotoLarge({
showCamera = true, showCamera = true,
showSimulation = true, showSimulation = true,
showZoomControls: showZoomControlsProp = true, showZoomControls: showZoomControlsProp = true,
shouldZoomOnFKeydown = true,
shouldShare = true, shouldShare = true,
shouldShareTag, shouldShareTag,
shouldShareCamera, shouldShareCamera,
@ -73,6 +74,7 @@ export default function PhotoLarge({
showCamera?: boolean showCamera?: boolean
showSimulation?: boolean showSimulation?: boolean
showZoomControls?: boolean showZoomControls?: boolean
shouldZoomOnFKeydown?: boolean
shouldShare?: boolean shouldShare?: boolean
shouldShareTag?: boolean shouldShareTag?: boolean
shouldShareCamera?: boolean shouldShareCamera?: boolean
@ -105,6 +107,7 @@ export default function PhotoLarge({
const { open } = useImageZoomControls( const { open } = useImageZoomControls(
refZoomControlsContainer, refZoomControlsContainer,
showZoomControls, showZoomControls,
shouldZoomOnFKeydown,
); );
const hasTitle = const hasTitle =
@ -141,18 +144,7 @@ export default function PhotoLarge({
} }
}; };
return ( const largePhotoContent =
<SiteGrid
containerRef={ref}
className={className}
contentMain={
<Link
href={pathForPhoto({ photo })}
className={clsx(arePhotosMatted &&
'flex items-center justify-center aspect-[3/2] bg-gray-100',
)}
prefetch={prefetch}
>
<div className={clsx( <div className={clsx(
arePhotosMatted && 'flex items-center justify-center', arePhotosMatted && 'flex items-center justify-center',
// Always specify height to ensure fallback doesn't collapse // Always specify height to ensure fallback doesn't collapse
@ -175,7 +167,26 @@ export default function PhotoLarge({
priority={priority} priority={priority}
/> />
</div> </div>
</div>;
const largePhotoContainerClassName = clsx(arePhotosMatted &&
'flex items-center justify-center aspect-[3/2] bg-gray-100',
);
return (
<SiteGrid
containerRef={ref}
className={className}
contentMain={showZoomControls
? <div className={largePhotoContainerClassName}>
{largePhotoContent}
</div> </div>
: <Link
href={pathForPhoto({ photo })}
className={largePhotoContainerClassName}
prefetch={prefetch}
>
{largePhotoContent}
</Link>} </Link>}
contentSide={ contentSide={
<DivDebugBaselineGrid className={clsx( <DivDebugBaselineGrid className={clsx(

View File

@ -31,6 +31,7 @@ export default function PhotosLarge({
priority={index <= 1} priority={index <= 1}
prefetchRelatedLinks={prefetchFirstPhotoLinks && index === 0} prefetchRelatedLinks={prefetchFirstPhotoLinks && index === 0}
revalidatePhoto={revalidatePhoto} revalidatePhoto={revalidatePhoto}
shouldZoomOnFKeydown={false}
onVisible={index === photos.length - 1 onVisible={index === photos.length - 1
? onLastPhotoVisible ? onLastPhotoVisible
: undefined} : undefined}

View File

@ -43,7 +43,7 @@
align-items: center; align-items: center;
justify-content: center; justify-content: center;
gap: 0.5rem; gap: 0.5rem;
padding: 2rem 0.25rem; padding: 0rem 0.25rem 2rem 0.25rem;
} }
.viewer-toolbar > ul > li { .viewer-toolbar > ul > li {
display: flex; display: flex;