mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-08 22:48:14 -05:00
Prevent zoom everywhere (ReactFlow is zoomable by default)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { Metadata } from 'next'
|
||||
import './globals.css'
|
||||
import { ZoomPrevention } from './zoom-prevention'
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'Sim Studio',
|
||||
@@ -14,7 +15,16 @@ export default function RootLayout({
|
||||
}) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body>{children}</body>
|
||||
<head>
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
|
||||
/>
|
||||
</head>
|
||||
<body>
|
||||
<ZoomPrevention />
|
||||
{children}
|
||||
</body>
|
||||
</html>
|
||||
)
|
||||
}
|
||||
|
||||
33
app/zoom-prevention.tsx
Normal file
33
app/zoom-prevention.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect } from 'react'
|
||||
|
||||
export function ZoomPrevention() {
|
||||
useEffect(() => {
|
||||
const preventZoom = (e: KeyboardEvent | WheelEvent) => {
|
||||
// Prevent zoom on ctrl/cmd + wheel
|
||||
if (e instanceof WheelEvent && (e.ctrlKey || e.metaKey)) {
|
||||
e.preventDefault()
|
||||
}
|
||||
|
||||
// Prevent zoom on ctrl/cmd + plus/minus/zero
|
||||
if (e instanceof KeyboardEvent && (e.ctrlKey || e.metaKey)) {
|
||||
if (e.key === '=' || e.key === '-' || e.key === '0') {
|
||||
e.preventDefault()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add event listeners
|
||||
document.addEventListener('wheel', preventZoom, { passive: false })
|
||||
document.addEventListener('keydown', preventZoom)
|
||||
|
||||
// Cleanup
|
||||
return () => {
|
||||
document.removeEventListener('wheel', preventZoom)
|
||||
document.removeEventListener('keydown', preventZoom)
|
||||
}
|
||||
}, [])
|
||||
|
||||
return null
|
||||
}
|
||||
Reference in New Issue
Block a user