Skip to content

Commit

Permalink
chore: define focus restoration explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik-stumpf committed Jul 3, 2024
1 parent 0a24199 commit 1f650db
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/components/common/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Modal = ({ children, ...rest }: ModalProps): JSX.Element => {
const transition = useBreakpointValue<any>(transitionValues)

return (
<ChakraModal motionPreset={transition} returnFocusOnClose={false} {...rest}>
<ChakraModal motionPreset={transition} {...rest}>
{children}
</ChakraModal>
)
Expand All @@ -22,7 +22,7 @@ const Alert = ({ children, ...rest }: AlertDialogProps): JSX.Element => {
const transition = useBreakpointValue<any>(transitionValues)

return (
<ChakraAlert motionPreset={transition} returnFocusOnClose={false} {...rest}>
<ChakraAlert motionPreset={transition} {...rest}>
{children}
</ChakraAlert>
)
Expand Down
9 changes: 8 additions & 1 deletion src/rewards/ContractCall/ContractCallCardMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import useGuildPermission from "components/[guild]/hooks/useGuildPermission"
import useWeb3ConnectionManager from "components/_app/Web3ConnectionManager/hooks/useWeb3ConnectionManager"
import EditNFTDescriptionModal from "./components/EditNFTDescriptionModal"
import EditNftModal from "./components/EditNftModal"
import { useRef } from "react"

type Props = {
platformGuildId: string
Expand All @@ -26,6 +27,7 @@ const ContractCallCardMenu = ({ platformGuildId }: Props): JSX.Element => {
onOpen: legacyOnOpen,
onClose: legacyOnClose,
} = useDisclosure()
const ref = useRef(null)

const isLegacy =
guildPlatform.platformGuildData.function ===
Expand All @@ -45,7 +47,11 @@ const ContractCallCardMenu = ({ platformGuildId }: Props): JSX.Element => {
return (
<>
<PlatformCardMenu>
<MenuItem icon={<PencilSimple />} onClick={isLegacy ? legacyOnOpen : onOpen}>
<MenuItem
icon={<PencilSimple />}
onClick={isLegacy ? legacyOnOpen : onOpen}
ref={ref}
>
{isLegacy ? "Edit NFT description" : "Edit NFT"}
</MenuItem>
<RemovePlatformMenuItem platformGuildId={platformGuildId} />
Expand All @@ -59,6 +65,7 @@ const ContractCallCardMenu = ({ platformGuildId }: Props): JSX.Element => {
/>
) : (
<EditNftModal
finalFocusRef={ref}
isOpen={isOpen}
onClose={onClose}
guildPlatform={guildPlatform}
Expand Down
6 changes: 4 additions & 2 deletions src/rewards/ContractCall/components/EditNftModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import useNftDetails from "components/[guild]/collect/hooks/useNftDetails"
import useGuild from "components/[guild]/hooks/useGuild"
import Button from "components/common/Button"
import { Modal } from "components/common/Modal"
import { useCallback } from "react"
import { MutableRefObject, useCallback } from "react"
import { FormProvider, useForm, useWatch } from "react-hook-form"
import { GuildPlatform } from "types"
import { formatUnits } from "viem"
Expand All @@ -31,9 +31,10 @@ type Props = {
isOpen: boolean
onClose: () => void
guildPlatform: GuildPlatform
finalFocusRef?: MutableRefObject<null>
}

const EditNftModal = ({ isOpen, onClose, guildPlatform }: Props) => {
const EditNftModal = ({ isOpen, onClose, guildPlatform, finalFocusRef }: Props) => {
const { chain, contractAddress } = guildPlatform.platformGuildData

const { roles } = useGuild()
Expand Down Expand Up @@ -61,6 +62,7 @@ const EditNftModal = ({ isOpen, onClose, guildPlatform }: Props) => {
scrollBehavior="inside"
colorScheme="dark"
size="4xl"
finalFocusRef={finalFocusRef}
>
<ModalOverlay />
<ModalContent>
Expand Down
5 changes: 4 additions & 1 deletion src/rewards/Forms/EditFormModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ import { FormProvider, useForm } from "react-hook-form"
import { uuidv7 } from "uuidv7"
import { z } from "zod"
import useEditForm from "./hooks/useEditForm"
import { MutableRefObject } from "react"

type Props = {
isOpen: boolean
onClose: () => void
form: Schemas["Form"]
finalFocusRef?: MutableRefObject<null>
}

const EditFormModal = ({ isOpen, onClose, form }: Props) => {
const EditFormModal = ({ isOpen, onClose, form, finalFocusRef }: Props) => {
const methods = useForm<z.input<typeof FormCreationSchema>>({
mode: "all",
resolver: zodResolver(FormCreationSchema),
Expand Down Expand Up @@ -93,6 +95,7 @@ const EditFormModal = ({ isOpen, onClose, form }: Props) => {
size="4xl"
colorScheme="dark"
scrollBehavior="inside"
finalFocusRef={finalFocusRef}
>
<ModalOverlay />
<ModalContent maxH="100vh !important">
Expand Down
13 changes: 11 additions & 2 deletions src/rewards/Forms/FormCardMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useGuildForm } from "components/[guild]/hooks/useGuildForms"
import LinkMenuItem from "components/common/LinkMenuItem"
import PlatformCardMenu from "../../components/[guild]/RolePlatforms/components/PlatformCard/components/PlatformCardMenu"
import EditFormModal from "./EditFormModal"
import { ElementRef, useRef } from "react"

type Props = {
platformGuildId: string
Expand All @@ -17,6 +18,7 @@ const FormCardMenu = ({ platformGuildId }: Props): JSX.Element => {
(gp) => gp.platformGuildId === platformGuildId
)
const formId = guildPlatform?.platformGuildData?.formId
const ref = useRef(null)

const { form } = useGuildForm(formId)

Expand All @@ -25,7 +27,7 @@ const FormCardMenu = ({ platformGuildId }: Props): JSX.Element => {
return (
<>
<PlatformCardMenu>
<MenuItem icon={<PencilSimple />} onClick={onOpen}>
<MenuItem icon={<PencilSimple />} onClick={onOpen} ref={ref}>
Edit form
</MenuItem>

Expand All @@ -39,7 +41,14 @@ const FormCardMenu = ({ platformGuildId }: Props): JSX.Element => {
<RemovePlatformMenuItem platformGuildId={platformGuildId} />
</PlatformCardMenu>

{!!form && <EditFormModal isOpen={isOpen} onClose={onClose} form={form} />}
{!!form && (
<EditFormModal
isOpen={isOpen}
onClose={onClose}
form={form}
finalFocusRef={ref}
/>
)}
</>
)
}
Expand Down

0 comments on commit 1f650db

Please sign in to comment.