Skip to content

Commit f91788f

Browse files
authored
Fix iOS detection and modal scrolling on Safari mobile (#325)
* Add better iOS detection * Fix scrolling for Safari browser
1 parent ec7bb76 commit f91788f

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/components/modal/Modal.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ const ModalOverlay = React.forwardRef<
3131
<DialogPrimitive.Overlay
3232
ref={ref}
3333
className={cn(
34-
"fixed inset-0 z-50 bg-black/30 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 dark:bg-neutral-950/70",
35-
"place-items-center overflow-y-auto",
34+
"fixed top-0 left-0 bottom-0 right-0 grid z-50 bg-black/30 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 dark:bg-neutral-950/70",
35+
"mx-auto place-items-start overflow-y-auto md:py-16",
3636
className,
3737
)}
3838
{...props}
@@ -65,7 +65,7 @@ const ModalContent = React.forwardRef<
6565
<DialogPrimitive.Content
6666
ref={ref}
6767
className={cn(
68-
"fixed left-[50%] top-0 md:top-[5%] z-50 grid w-full translate-x-[-50%] border border-neutral-200 bg-white py-6 dark:shadow-lg shadow-sm duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=open]:slide-in-from-left-1/2 ] sm:rounded-lg md:w-full dark:border-nb-gray-900 dark:bg-nb-gray",
68+
"mx-auto relative top-0 z-50 grid w-full border border-neutral-200 bg-white py-6 dark:shadow-lg shadow-sm duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1 data-[state=open]:slide-in-from-left-1 sm:rounded-lg md:w-full dark:border-nb-gray-900 dark:bg-nb-gray",
6969
className,
7070
maxWidthClass,
7171
)}

src/hooks/useOperatingSystem.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ import { OperatingSystem } from "@/interfaces/OperatingSystem";
55
export default function useOperatingSystem() {
66
const isBrowser = typeof window !== "undefined";
77
const userAgent = isBrowser ? navigator.userAgent.toLowerCase() : "";
8+
const iOS = isBrowser
9+
? /(iP*)/g.test(navigator.userAgent) && navigator.maxTouchPoints > 2
10+
: false;
11+
if (iOS) return OperatingSystem.IOS;
812
return getOperatingSystem(userAgent);
913
}
1014

1115
export const getOperatingSystem = (os: string) => {
1216
if (os.includes("darwin")) return OperatingSystem.APPLE as const;
1317
if (os.includes("mac")) return OperatingSystem.APPLE as const;
1418
if (os.includes("android")) return OperatingSystem.ANDROID as const;
15-
if (os.includes("ios")) return OperatingSystem.APPLE as const;
19+
if (os.includes("ios")) return OperatingSystem.IOS as const;
1620
if (os.includes("win")) return OperatingSystem.WINDOWS as const;
1721
return OperatingSystem.LINUX as const;
1822
};

0 commit comments

Comments
 (0)