Focus markdown link bubble input from ref (#3316)

This commit is contained in:
Neil 2026-05-30 18:11:41 -07:00 committed by GitHub
parent 71f94a49eb
commit 35bcf4af49
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 6 deletions

View File

@ -1,4 +1,4 @@
import React, { useEffect, useRef, useState } from 'react'
import React, { useCallback, useState } from 'react'
import type { Editor } from '@tiptap/react'
import { ExternalLink, Pencil, Unlink } from 'lucide-react'
@ -38,16 +38,20 @@ function LinkEditInput({
onCancel: () => void
}): React.JSX.Element {
const [value, setValue] = useState(initialHref)
const ref = useRef<HTMLInputElement>(null)
useEffect(() => {
ref.current?.focus()
ref.current?.select()
const setInputElement = useCallback((input: HTMLInputElement | null) => {
if (!input) {
return
}
// Why: edit mode should start with the current URL selected, but typing
// changes must not re-select the field on every value update.
input.focus()
input.select()
}, [])
return (
<input
ref={ref}
ref={setInputElement}
value={value}
onChange={(e) => setValue(e.target.value)}
onKeyDown={(e) => {