2
0

🐛 (js) Fix popup closing on bot click

This commit is contained in:
Baptiste Arnaud
2023-03-13 10:27:40 +01:00
parent a66a1e8226
commit 4ae9ea32e4
4 changed files with 4 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@typebot.io/js", "name": "@typebot.io/js",
"version": "0.0.26", "version": "0.0.27",
"description": "Javascript library to display typebots on your website", "description": "Javascript library to display typebots on your website",
"type": "module", "type": "module",
"main": "dist/index.js", "main": "dist/index.js",

View File

@@ -4,6 +4,7 @@ declare module 'solid-js' {
namespace JSX { namespace JSX {
interface CustomEvents { interface CustomEvents {
click: MouseEvent click: MouseEvent
pointerdown: PointerEvent
} }
} }
} }

View File

@@ -21,8 +21,6 @@ export type PopupProps = BotProps &
} }
export const Popup = (props: PopupProps) => { export const Popup = (props: PopupProps) => {
let botContainer: HTMLDivElement | undefined
const [popupProps, botProps] = splitProps(props, [ const [popupProps, botProps] = splitProps(props, [
'onOpen', 'onOpen',
'onClose', 'onClose',
@@ -92,7 +90,6 @@ export const Popup = (props: PopupProps) => {
popupProps.onOpen?.() popupProps.onOpen?.()
document.body.style.overflow = 'hidden' document.body.style.overflow = 'hidden'
document.addEventListener('pointerdown', closeBot) document.addEventListener('pointerdown', closeBot)
botContainer?.addEventListener('pointerdown', stopPropagation)
} }
const closeBot = () => { const closeBot = () => {
@@ -100,7 +97,6 @@ export const Popup = (props: PopupProps) => {
popupProps.onClose?.() popupProps.onClose?.()
document.body.style.overflow = 'auto' document.body.style.overflow = 'auto'
document.removeEventListener('pointerdown', closeBot) document.removeEventListener('pointerdown', closeBot)
botContainer?.removeEventListener('pointerdown', stopPropagation)
} }
const toggleBot = () => { const toggleBot = () => {
@@ -126,7 +122,7 @@ export const Popup = (props: PopupProps) => {
'background-color': 'background-color':
props.theme?.backgroundColor ?? 'transparent', props.theme?.backgroundColor ?? 'transparent',
}} }}
ref={botContainer} on:pointerdown={stopPropagation}
> >
<Bot {...botProps} prefilledVariables={prefilledVariables()} /> <Bot {...botProps} prefilledVariables={prefilledVariables()} />
</div> </div>

View File

@@ -1,6 +1,6 @@
{ {
"name": "@typebot.io/react", "name": "@typebot.io/react",
"version": "0.0.26", "version": "0.0.27",
"description": "React library to display typebots on your website", "description": "React library to display typebots on your website",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",