From 5292de84f14d65ffba9884e9083f44951aa981bf Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 9 Jul 2024 10:19:52 +0200 Subject: [PATCH] Revert "fix: focus on close modal (#3967)" This reverts commit 3a97e744a0a955eae9dc0e9c831a98647e0be068. --- .changeset/beige-ladybugs-kiss.md | 5 +++++ packages/ui/src/components/Modal/Disclosure.tsx | 11 +++++++++-- packages/ui/src/components/Modal/index.tsx | 7 ++----- packages/ui/src/components/Modal/types.ts | 1 - 4 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 .changeset/beige-ladybugs-kiss.md diff --git a/.changeset/beige-ladybugs-kiss.md b/.changeset/beige-ladybugs-kiss.md new file mode 100644 index 0000000000..86eaf810d3 --- /dev/null +++ b/.changeset/beige-ladybugs-kiss.md @@ -0,0 +1,5 @@ +--- +"@ultraviolet/ui": patch +--- + +Hotfix of `` component not working properly with disclosure diff --git a/packages/ui/src/components/Modal/Disclosure.tsx b/packages/ui/src/components/Modal/Disclosure.tsx index 1fa8836dca..476e1e9b64 100644 --- a/packages/ui/src/components/Modal/Disclosure.tsx +++ b/packages/ui/src/components/Modal/Disclosure.tsx @@ -1,5 +1,11 @@ import type { PropsWithRef } from 'react' -import { cloneElement, isValidElement, useEffect, useMemo } from 'react' +import { + cloneElement, + createRef, + isValidElement, + useEffect, + useMemo, +} from 'react' import type { DisclosureProps } from './types' export const Disclosure = ({ @@ -9,8 +15,9 @@ export const Disclosure = ({ handleClose, toggle, id, - disclosureRef, }: DisclosureProps) => { + const disclosureRef = createRef() + useEffect(() => { const element = disclosureRef.current element?.addEventListener('click', handleOpen) diff --git a/packages/ui/src/components/Modal/index.tsx b/packages/ui/src/components/Modal/index.tsx index 7bdaa8e88b..bda4feaa13 100644 --- a/packages/ui/src/components/Modal/index.tsx +++ b/packages/ui/src/components/Modal/index.tsx @@ -1,7 +1,7 @@ import styled from '@emotion/styled' import type { ReactElement, ReactNode } from 'react' import type React from 'react' -import { useCallback, useId, useRef, useState } from 'react' +import { useCallback, useId, useState } from 'react' import { Button } from '../Button' import { Dialog } from './Dialog' import { Disclosure } from './Disclosure' @@ -77,7 +77,6 @@ export const Modal = ({ // Used for disclosure usage only const [visible, setVisible] = useState(false) const controlId = useId() - const disclosureRef = useRef(null) const handleOpen = useCallback(() => { setVisible(true) @@ -93,8 +92,7 @@ export const Modal = ({ } setVisible(false) } - disclosureRef.current?.focus() - }, [disclosureRef, onBeforeClose, onClose]) + }, [onBeforeClose, onClose]) const handleToggle = useCallback(() => { setVisible(current => !current) @@ -113,7 +111,6 @@ export const Modal = ({ handleClose={handleClose} visible={visible} toggle={handleToggle} - disclosureRef={disclosureRef} /> ) : null} } export type DialogProps = {