diff --git a/apps/builder/src/features/theme/components/general/BackgroundContent.tsx b/apps/builder/src/features/theme/components/general/BackgroundContent.tsx index 7aa5ed0f2..0222c5444 100644 --- a/apps/builder/src/features/theme/components/general/BackgroundContent.tsx +++ b/apps/builder/src/features/theme/components/general/BackgroundContent.tsx @@ -4,11 +4,12 @@ import { Flex, Popover, PopoverContent, - PopoverTrigger, Text, Image, Button, Portal, + PopoverAnchor, + useDisclosure, } from '@chakra-ui/react' import { isNotEmpty } from '@typebot.io/lib' import { Background } from '@typebot.io/schemas' @@ -20,6 +21,7 @@ import { defaultBackgroundType, } from '@typebot.io/schemas/features/typebot/theme/constants' import { useTranslate } from '@tolgee/react' +import { useOutsideClick } from '@/hooks/useOutsideClick' type BackgroundContentProps = { background?: Background @@ -30,48 +32,65 @@ export const BackgroundContent = ({ background, onBackgroundContentChange, }: BackgroundContentProps) => { + const { isOpen, onClose, onOpen } = useDisclosure() const { t } = useTranslate() const { typebot } = useTypebot() const handleContentChange = (content: string) => onBackgroundContentChange(content) + const popoverContainerRef = React.useRef(null) + + useOutsideClick({ + ref: popoverContainerRef, + handler: onClose, + isEnabled: isOpen, + }) if ((background?.type ?? defaultBackgroundType) === BackgroundType.IMAGE) { if (!typebot) return null return ( - - - {isNotEmpty(background?.content) ? ( - {t('theme.sideMenu.global.background.image.alt')} - ) : ( - - )} - - - - - - - + + + + {isNotEmpty(background?.content) ? ( + {t('theme.sideMenu.global.background.image.alt')} + ) : ( + + )} + + + e.stopPropagation()} + onPointerDown={(e) => e.stopPropagation()} + > + + + + + ) } if ((background?.type ?? defaultBackgroundType) === BackgroundType.COLOR) {