Skip to content

Commit

Permalink
馃悰 (editor) Fix multiple text editor focus
Browse files Browse the repository at this point in the history
Closes #1312
  • Loading branch information
baptisteArno committed Mar 15, 2024
1 parent 065a70e commit 9b9282e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ export const PreCheckoutModal = ({
<Select
placeholder={t('billing.preCheckoutModal.taxId.placeholder')}
items={vatCodeLabels}
isPopoverMatchingInputWidth={false}
onSelect={updateVatType}
/>
<TextInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ export const BlockNode = ({
const { mouseOverBlock, setMouseOverBlock } = useBlockDnd()
const { typebot, updateBlock } = useTypebot()
const [isConnecting, setIsConnecting] = useState(false)
const [isPopoverOpened, setIsPopoverOpened] = useState(
openedBlockId === block.id
)
const [isEditing, setIsEditing] = useState<boolean>(
isTextBubbleBlock(block) && (block.content?.richText?.length ?? 0) === 0
)
const blockRef = useRef<HTMLDivElement | null>(null)

const isPreviewing =
Expand All @@ -105,7 +99,7 @@ export const BlockNode = ({
ref: blockRef,
onDrag,
isDisabled: !onMouseDown,
deps: [isEditing],
deps: [openedBlockId],
})

const {
Expand Down Expand Up @@ -153,13 +147,11 @@ export const BlockNode = ({
const handleCloseEditor = (content: TElement[]) => {
const updatedBlock = { ...block, content: { richText: content } }
updateBlock(indices, updatedBlock)
setIsEditing(false)
}

const handleClick = (e: React.MouseEvent) => {
setFocusedGroupId(groupId)
e.stopPropagation()
if (isTextBubbleBlock(block) && !isReadOnly) setIsEditing(true)
setOpenedBlockId(block.id)
}

Expand All @@ -174,10 +166,6 @@ export const BlockNode = ({
const handleContentChange = (content: BubbleBlockContent) =>
updateBlock(indices, { ...block, content } as Block)

useEffect(() => {
setIsPopoverOpened(openedBlockId === block.id)
}, [block.id, openedBlockId])

useEffect(() => {
if (!blockRef.current) return
const blockElement = blockRef.current
Expand Down Expand Up @@ -230,7 +218,7 @@ export const BlockNode = ({
return edge.to.blockId === block.id
})

return isEditing && isTextBubbleBlock(block) ? (
return openedBlockId === block.id && isTextBubbleBlock(block) ? (
<TextBubbleEditor
id={block.id}
initialValue={block.content?.richText ?? []}
Expand All @@ -253,7 +241,7 @@ export const BlockNode = ({
<Popover
placement="left"
isLazy
isOpen={isPopoverOpened}
isOpen={openedBlockId === block.id}
closeOnBlur={false}
>
<PopoverTrigger>
Expand Down

0 comments on commit 9b9282e

Please sign in to comment.