Skip to content

Commit 83f48af

Browse files
committed
Small fix
1 parent 670c50e commit 83f48af

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

packages/react/src/components/FormattingToolbar/DefaultButtons/CreateLinkButton.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { useEditorState } from "../../../hooks/useEditorState.js";
1919
import { useExtension } from "../../../hooks/useExtension.js";
2020
import { useDictionary } from "../../../i18n/dictionary.js";
2121
import { EditLinkMenuItems } from "../../LinkToolbar/EditLinkMenuItems.js";
22-
import { useEditorChange } from "../../../hooks/useEditorChange.js";
2322

2423
function checkLinkInSchema(
2524
editor: BlockNoteEditor<BlockSchema, any, StyleSchema>,
@@ -54,11 +53,6 @@ export const CreateLinkButton = () => {
5453
return () => showSelection(false, "createLinkButton");
5554
}, [showPopover, showSelection]);
5655

57-
useEditorChange(() => {
58-
// Close the popover when the editor is updated after a link has been created
59-
setShowPopover(false);
60-
}, editor);
61-
6256
const state = useEditorState({
6357
editor,
6458
selector: ({ editor }) => {
@@ -90,6 +84,11 @@ export const CreateLinkButton = () => {
9084
};
9185
},
9286
});
87+
useEffect(() => {
88+
if (state?.url === undefined) {
89+
setShowPopover(false);
90+
}
91+
}, [state?.url]);
9392

9493
// Makes Ctrl+K/Meta+K open link creation popover.
9594
useEffect(() => {
@@ -129,7 +128,7 @@ export const CreateLinkButton = () => {
129128
dict.generic.ctrl_shortcut,
130129
)}
131130
icon={<RiLink />}
132-
onClick={() => setShowPopover(open => !open)}
131+
onClick={() => setShowPopover((open) => !open)}
133132
/>
134133
</Components.Generic.Popover.Trigger>
135134
<Components.Generic.Popover.Content

0 commit comments

Comments
 (0)