Skip to content

Commit 49a853d

Browse files
committed
feat: enhance ExportImportModal with textarea focus and selection on open
1 parent 9f2df8b commit 49a853d

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/components/ExportImportModal.tsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect } from "react";
1+
import { useState, useEffect, useRef } from "react";
22
import type { EventData } from "../types/events";
33

44
interface ExportImportModalProps {
@@ -18,6 +18,8 @@ export function ExportImportModal({
1818
}: ExportImportModalProps) {
1919
const [importText, setImportText] = useState("");
2020
const [copySuccess, setCopySuccess] = useState(false);
21+
const exportTextareaRef = useRef<HTMLTextAreaElement>(null);
22+
const importTextareaRef = useRef<HTMLTextAreaElement>(null);
2123

2224
const exportJson = JSON.stringify(events, null, 2);
2325

@@ -57,6 +59,22 @@ export function ExportImportModal({
5759
}
5860
}, [isOpen]);
5961

62+
// Focus the appropriate textarea when modal opens
63+
useEffect(() => {
64+
if (isOpen) {
65+
// Small delay to ensure modal is fully rendered
66+
const timer = setTimeout(() => {
67+
if (mode === 'export' && exportTextareaRef.current) {
68+
exportTextareaRef.current.focus();
69+
exportTextareaRef.current.select(); // Select all text for easy copying
70+
} else if (mode === 'import' && importTextareaRef.current) {
71+
importTextareaRef.current.focus();
72+
}
73+
}, 100);
74+
return () => clearTimeout(timer);
75+
}
76+
}, [isOpen, mode]);
77+
6078
const handleCopy = async () => {
6179
try {
6280
await navigator.clipboard.writeText(exportJson);
@@ -119,6 +137,7 @@ export function ExportImportModal({
119137
</button>
120138
</div>
121139
<textarea
140+
ref={exportTextareaRef}
122141
value={exportJson}
123142
readOnly
124143
className="flex-1 bg-bg border border-sub rounded p-3 text-text font-mono text-sm resize-none"
@@ -129,6 +148,7 @@ export function ExportImportModal({
129148
<div className="flex flex-col flex-1">
130149
<p className="text-text mb-2">Paste the JSON data below:</p>
131150
<textarea
151+
ref={importTextareaRef}
132152
value={importText}
133153
onChange={(e) => setImportText(e.target.value)}
134154
placeholder="Paste exported JSON data here..."

0 commit comments

Comments
 (0)