🚑 Fix variable search button input not auto opening
This commit is contained in:
@ -22,13 +22,7 @@ import { EditIcon, PlusIcon, TrashIcon } from '@/components/icons'
|
|||||||
import { useTypebot } from '@/features/editor/providers/TypebotProvider'
|
import { useTypebot } from '@/features/editor/providers/TypebotProvider'
|
||||||
import { createId } from '@paralleldrive/cuid2'
|
import { createId } from '@paralleldrive/cuid2'
|
||||||
import { Variable } from '@typebot.io/schemas'
|
import { Variable } from '@typebot.io/schemas'
|
||||||
import React, {
|
import React, { useState, useRef, ChangeEvent, ReactNode } from 'react'
|
||||||
useState,
|
|
||||||
useRef,
|
|
||||||
ChangeEvent,
|
|
||||||
useEffect,
|
|
||||||
ReactNode,
|
|
||||||
} from 'react'
|
|
||||||
import { byId, isDefined, isNotDefined } from '@typebot.io/lib'
|
import { byId, isDefined, isNotDefined } from '@typebot.io/lib'
|
||||||
import { useOutsideClick } from '@/hooks/useOutsideClick'
|
import { useOutsideClick } from '@/hooks/useOutsideClick'
|
||||||
import { useParentModal } from '@/features/graph/providers/ParentModalProvider'
|
import { useParentModal } from '@/features/graph/providers/ParentModalProvider'
|
||||||
@ -63,7 +57,9 @@ export const VariableSearchInput = ({
|
|||||||
...inputProps
|
...inputProps
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const focusedItemBgColor = useColorModeValue('gray.200', 'gray.700')
|
const focusedItemBgColor = useColorModeValue('gray.200', 'gray.700')
|
||||||
const { onOpen, onClose, isOpen } = useDisclosure()
|
const { onOpen, onClose, isOpen } = useDisclosure({
|
||||||
|
defaultIsOpen: autoFocus,
|
||||||
|
})
|
||||||
const { typebot, createVariable, deleteVariable, updateVariable } =
|
const { typebot, createVariable, deleteVariable, updateVariable } =
|
||||||
useTypebot()
|
useTypebot()
|
||||||
const variables = typebot?.variables ?? []
|
const variables = typebot?.variables ?? []
|
||||||
@ -89,10 +85,6 @@ export const VariableSearchInput = ({
|
|||||||
isEnabled: isOpen,
|
isEnabled: isOpen,
|
||||||
})
|
})
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (autoFocus) onOpen()
|
|
||||||
}, [autoFocus, onOpen])
|
|
||||||
|
|
||||||
const onInputChange = (e: ChangeEvent<HTMLInputElement>) => {
|
const onInputChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
setInputValue(e.target.value)
|
setInputValue(e.target.value)
|
||||||
if (e.target.value === '') {
|
if (e.target.value === '') {
|
||||||
@ -244,6 +236,7 @@ export const VariableSearchInput = ({
|
|||||||
>
|
>
|
||||||
{isCreateVariableButtonDisplayed && (
|
{isCreateVariableButtonDisplayed && (
|
||||||
<Button
|
<Button
|
||||||
|
as="li"
|
||||||
ref={createVariableItemRef}
|
ref={createVariableItemRef}
|
||||||
role="menuitem"
|
role="menuitem"
|
||||||
minH="40px"
|
minH="40px"
|
||||||
@ -277,6 +270,8 @@ export const VariableSearchInput = ({
|
|||||||
: idx
|
: idx
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
|
as="li"
|
||||||
|
cursor="pointer"
|
||||||
ref={(el) => (itemsRef.current[idx] = el)}
|
ref={(el) => (itemsRef.current[idx] = el)}
|
||||||
role="menuitem"
|
role="menuitem"
|
||||||
minH="40px"
|
minH="40px"
|
||||||
|
Reference in New Issue
Block a user