mirror of
https://github.com/remvze/moodist.git
synced 2025-09-29 15:30:49 -04:00
feat: add autofocus for note
This commit is contained in:
parent
ab9d47befb
commit
24a53c81df
@ -1,3 +1,4 @@
|
||||
import { useRef, useEffect } from 'react';
|
||||
import { BiTrash } from 'react-icons/bi/index';
|
||||
import { LuCopy, LuDownload } from 'react-icons/lu/index';
|
||||
import { FaCheck } from 'react-icons/fa6/index';
|
||||
@ -18,6 +19,8 @@ interface NotepadProps {
|
||||
}
|
||||
|
||||
export function Notepad({ onClose, show }: NotepadProps) {
|
||||
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||
|
||||
const note = useNoteStore(state => state.note);
|
||||
const history = useNoteStore(state => state.history);
|
||||
const write = useNoteStore(state => state.write);
|
||||
@ -28,6 +31,14 @@ export function Notepad({ onClose, show }: NotepadProps) {
|
||||
|
||||
const { copy, copying } = useCopy();
|
||||
|
||||
useEffect(() => {
|
||||
if (show && textareaRef.current) {
|
||||
setTimeout(() => {
|
||||
textareaRef.current?.focus();
|
||||
}, 10);
|
||||
}
|
||||
}, [show]);
|
||||
|
||||
return (
|
||||
<Modal show={show} wide onClose={onClose}>
|
||||
<header className={styles.header}>
|
||||
@ -57,6 +68,7 @@ export function Notepad({ onClose, show }: NotepadProps) {
|
||||
className={styles.textarea}
|
||||
dir="auto"
|
||||
placeholder="What is on your mind?"
|
||||
ref={textareaRef}
|
||||
value={note}
|
||||
onChange={e => write(e.target.value)}
|
||||
/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user