The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
added focus trap on modals
msmpsfe518c413da3
diff --git a/components/shared/modal.tsx b/components/shared/modal.tsxindex c4098c214b..980b16a185 100644--- a/components/shared/modal.tsx+++ b/components/shared/modal.tsx@@ -7,6 +7,7 @@ import {} from "react";import { useRouter } from "next/router";import { motion, AnimatePresence, useAnimation } from "framer-motion";+import FocusTrap from "focus-trap-react";export default function Modal({children,@@ -68,49 +69,53 @@ export default function Modal({<AnimatePresence>{showModal && (<>- <motion.div- ref={mobileModalRef}- key="mobile-modal"- className="group fixed bottom-0 inset-x-0 z-40 w-screen sm:hidden cursor-grab active:cursor-grabbing"- initial={{ y: "100%" }}- animate={controls}- exit={{ y: "100%" }}- transition={transitionProps}- drag="y"- dragDirectionLock- onDragEnd={handleDragEnd}- dragElastic={{ top: 0, bottom: 1 }}- dragConstraints={{ top: 0, bottom: 0 }}- >- <div- className={`h-7 ${bgColor} w-full flex items-center justify-center rounded-t-4xl border-t border-gray-200 -mb-1`}- >- <div className="rounded-full h-1 w-6 -mr-1 bg-gray-300 group-active:rotate-12 transition-all" />- <div className="rounded-full h-1 w-6 bg-gray-300 group-active:-rotate-12 transition-all" />+ <FocusTrap>+ <div>+ <motion.div+ ref={mobileModalRef}+ key="mobile-modal"+ className="group fixed bottom-0 inset-x-0 z-40 w-screen sm:hidden cursor-grab active:cursor-grabbing"+ initial={{ y: "100%" }}+ animate={controls}+ exit={{ y: "100%" }}+ transition={transitionProps}+ drag="y"+ dragDirectionLock+ onDragEnd={handleDragEnd}+ dragElastic={{ top: 0, bottom: 1 }}+ dragConstraints={{ top: 0, bottom: 0 }}+ >+ <div+ className={`h-7 ${bgColor} w-full flex items-center justify-center rounded-t-4xl border-t border-gray-200 -mb-1`}+ >+ <div className="rounded-full h-1 w-6 -mr-1 bg-gray-300 group-active:rotate-12 transition-all" />+ <div className="rounded-full h-1 w-6 bg-gray-300 group-active:-rotate-12 transition-all" />+ </div>+ {children}+ </motion.div>+ <motion.div+ ref={desktopModalRef}+ key="desktop-modal"+ className="fixed inset-0 z-40 min-h-screen hidden sm:flex items-center justify-center"+ initial={{ scale: 0.95 }}+ animate={{ scale: 1 }}+ exit={{ scale: 0.95 }}+ onClick={(e) => {+ if (desktopModalRef.current === e.target) closeModal();+ }}+ >+ {children}+ </motion.div>+ <motion.div+ key="backdrop"+ className="fixed inset-0 z-30 bg-gray-100 bg-opacity-10 backdrop-blur"+ initial={{ opacity: 0 }}+ animate={{ opacity: 1 }}+ exit={{ opacity: 0 }}+ onClick={closeModal}+ /></div>- {children}- </motion.div>- <motion.div- ref={desktopModalRef}- key="desktop-modal"- className="fixed inset-0 z-40 min-h-screen hidden sm:flex items-center justify-center"- initial={{ scale: 0.95 }}- animate={{ scale: 1 }}- exit={{ scale: 0.95 }}- onClick={(e) => {- if (desktopModalRef.current === e.target) closeModal();- }}- >- {children}- </motion.div>- <motion.div- key="backdrop"- className="fixed inset-0 z-30 bg-gray-100 bg-opacity-10 backdrop-blur"- initial={{ opacity: 0 }}- animate={{ opacity: 1 }}- exit={{ opacity: 0 }}- onClick={closeModal}- />+ </FocusTrap></>)}</AnimatePresence>diff --git a/package.json b/package.jsonindex f25ed1998c..258cfae5aa 100644--- a/package.json+++ b/package.json@@ -32,6 +32,7 @@"@visx/tooltip": "^2.10.0","cloudinary": "^1.32.0","cobe": "^0.6.2",+ "focus-trap-react": "^10.0.0","framer-motion": "^7.2.1","html-escaper": "^3.0.3","i": "^0.3.7",diff --git a/yarn.lock b/yarn.lockindex e65b973aec..a0508968a1 100644--- a/yarn.lock+++ b/yarn.lock@@ -1728,6 +1728,21 @@ fill-range@^7.0.1:dependencies:to-regex-range "^5.0.1"+focus-trap-react@^10.0.0:+ version "10.0.0"+ resolved "https://registry.yarnpkg.com/focus-trap-react/-/focus-trap-react-10.0.0.tgz#9e41ddd0b869db577dfe670611648d97736b9188"+ integrity sha512-I0tReLdpmCwWuVb6YAmOD+S9KHj0GrlIWmnVJf61j2NHxiIg7DbrsabPmtPC+1yzGJrsy+/iTZiqXtStjlBQcA==+ dependencies:+ focus-trap "^7.0.0"+ tabbable "^6.0.0"++focus-trap@^7.0.0:+ version "7.0.0"+ resolved "https://registry.yarnpkg.com/focus-trap/-/focus-trap-7.0.0.tgz#4e2cd9aab5b673e2cbad945c52bd232f6160c2cb"+ integrity sha512-uT4Bl8TwU+5vVAx/DHil/1eVS54k9unqhK/vGy2KSh7esPmqgC0koAB9J2sJ+vtj8+vmiFyGk2unLkhNLQaxoA==+ dependencies:+ tabbable "^6.0.0"+fraction.js@^4.2.0:version "4.2.0"resolved "https://registry.npmjs.org/fraction.js/-/fraction.js-4.2.0.tgz"@@ -3523,6 +3538,11 @@ swr@^2.0.0-beta.1:dependencies:use-sync-external-store "^1.1.0"+tabbable@^6.0.0:+ version "6.0.0"+ resolved "https://registry.yarnpkg.com/tabbable/-/tabbable-6.0.0.tgz#7f95ea69134e9335979092ba63866fe67b521b01"+ integrity sha512-SxhZErfHc3Yozz/HLAl/iPOxuIj8AtUw13NRewVOjFW7vbsqT1f3PuiHrPQbUkRcLNEgAedAv2DnjLtzynJXiw==+tailwind-scrollbar-hide@^1.1.7:version "1.1.7"resolved "https://registry.npmjs.org/tailwind-scrollbar-hide/-/tailwind-scrollbar-hide-1.1.7.tgz"