Skip to content

Commit 04eb997

Browse files
committed
fix: autoFocus attr not working
1 parent e524b85 commit 04eb997

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/App.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ let keyword = ''
1010

1111
export default function App() {
1212
const dialogRef = useRef<HTMLDialogElement>(null)
13+
const inputRef = useRef<HTMLInputElement>(null)
1314
const [comments, setComments] = useState<Reply[]>()
1415
const promiseRef = useRef<Promise<Reply[]> | null>(null)
1516

@@ -33,7 +34,7 @@ export default function App() {
3334
<button onClick={() => dialogRef.current?.close()}>X</button>
3435
</div>
3536
<input
36-
autoFocus
37+
ref={inputRef}
3738
placeholder='搜索评论'
3839
onKeyDown={(e) => {
3940
if (e.key === 'Enter' && promiseRef.current) {
@@ -57,6 +58,7 @@ export default function App() {
5758
<button
5859
onClick={() => {
5960
dialogRef.current?.showModal()
61+
inputRef.current?.focus()
6062
const videoId = extractVideoId(window.location.href)
6163
promiseRef.current = fetchComments(videoId)
6264
}}

0 commit comments

Comments
 (0)