Attempt to wrap modal root onopenchange to handle pointer events

This commit is contained in:
Jackson Harper
2024-03-04 13:02:18 +08:00
parent 07f771c45f
commit b719a8aa74
2 changed files with 21 additions and 4 deletions

View File

@ -6,6 +6,7 @@ import {
import { VStack, HStack } from '../elements/LayoutPrimitives'
import { Button } from '../elements/Button'
import { StyledText } from '../elements/StyledText'
import { useCallback } from 'react'
type ConfirmationModalProps = {
message?: string
@ -18,8 +19,15 @@ type ConfirmationModalProps = {
}
export function ConfirmationModal(props: ConfirmationModalProps): JSX.Element {
const safeOnOpenChange = useCallback(
(open: boolean) => {
document.body.style.removeProperty('pointer-events')
props.onOpenChange(open)
},
[props]
)
return (
<ModalRoot defaultOpen onOpenChange={props.onOpenChange}>
<ModalRoot defaultOpen onOpenChange={safeOnOpenChange}>
<ModalOverlay />
<ModalContent css={{ bg: '$grayBg', maxWidth: '20em', zIndex: '20' }}>
<VStack alignment="center" distribution="center" css={{ p: '15px' }}>

View File

@ -31,8 +31,9 @@ export function SetLabelsModal(props: SetLabelsModalProps): JSX.Element {
const availableLabels = useGetLabelsQuery()
const [tabCount, setTabCount] = useState(-1)
const [tabStartValue, setTabStartValue] = useState('')
const [errorMessage, setErrorMessage] =
useState<string | undefined>(undefined)
const [errorMessage, setErrorMessage] = useState<string | undefined>(
undefined
)
const errorTimeoutRef = useRef<NodeJS.Timeout | undefined>()
const [highlightLastLabel, setHighlightLastLabel] = useState(false)
@ -169,8 +170,16 @@ export function SetLabelsModal(props: SetLabelsModalProps): JSX.Element {
}
}, [highlightLastLabel, selectedLabels, dispatchLabels])
const safeOnOpenChange = useCallback(
(open: boolean) => {
document.body.style.removeProperty('pointer-events')
props.onOpenChange(open)
},
[props]
)
return (
<ModalRoot defaultOpen onOpenChange={props.onOpenChange}>
<ModalRoot defaultOpen onOpenChange={safeOnOpenChange}>
<Dialog.Portal>
<ModalOverlay />
<ModalContent