chore: fix link editor dismiss
This commit is contained in:
@@ -4,7 +4,7 @@ import { KeyboardKey } from '@standardnotes/ui-services'
|
|||||||
import { IconComponent } from '../../Lexical/Theme/IconComponent'
|
import { IconComponent } from '../../Lexical/Theme/IconComponent'
|
||||||
import { sanitizeUrl } from '../../Lexical/Utils/sanitizeUrl'
|
import { sanitizeUrl } from '../../Lexical/Utils/sanitizeUrl'
|
||||||
import { TOGGLE_LINK_COMMAND } from '@lexical/link'
|
import { TOGGLE_LINK_COMMAND } from '@lexical/link'
|
||||||
import { useCallback, useState } from 'react'
|
import { useCallback, useState, useRef } from 'react'
|
||||||
import { GridSelection, LexicalEditor, NodeSelection, RangeSelection } from 'lexical'
|
import { GridSelection, LexicalEditor, NodeSelection, RangeSelection } from 'lexical'
|
||||||
import { classNames } from '@standardnotes/snjs'
|
import { classNames } from '@standardnotes/snjs'
|
||||||
|
|
||||||
@@ -19,6 +19,7 @@ type Props = {
|
|||||||
|
|
||||||
const LinkEditor = ({ linkUrl, isEditMode, setEditMode, editor, lastSelection, isAutoLink }: Props) => {
|
const LinkEditor = ({ linkUrl, isEditMode, setEditMode, editor, lastSelection, isAutoLink }: Props) => {
|
||||||
const [editedLinkUrl, setEditedLinkUrl] = useState('')
|
const [editedLinkUrl, setEditedLinkUrl] = useState('')
|
||||||
|
const editModeContainer = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
const handleLinkSubmission = () => {
|
const handleLinkSubmission = () => {
|
||||||
if (lastSelection !== null) {
|
if (lastSelection !== null) {
|
||||||
@@ -36,7 +37,7 @@ const LinkEditor = ({ linkUrl, isEditMode, setEditMode, editor, lastSelection, i
|
|||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return isEditMode ? (
|
return isEditMode ? (
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2" ref={editModeContainer}>
|
||||||
<input
|
<input
|
||||||
id="link-input"
|
id="link-input"
|
||||||
ref={focusInput}
|
ref={focusInput}
|
||||||
@@ -53,6 +54,11 @@ const LinkEditor = ({ linkUrl, isEditMode, setEditMode, editor, lastSelection, i
|
|||||||
setEditMode(false)
|
setEditMode(false)
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
onBlur={(event) => {
|
||||||
|
if (!editModeContainer.current?.contains(event.relatedTarget as Node)) {
|
||||||
|
setEditMode(false)
|
||||||
|
}
|
||||||
|
}}
|
||||||
className="flex-grow rounded-sm bg-contrast p-1 text-text sm:min-w-[40ch]"
|
className="flex-grow rounded-sm bg-contrast p-1 text-text sm:min-w-[40ch]"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
|
|||||||
Reference in New Issue
Block a user