"use client"; import { useRef, useEffect, useCallback } from "react"; import { Input } from "@kandev/ui/input"; import { FileIcon } from "@/components/ui/file-icon"; type InlineFileInputProps = { depth: number; onSubmit: (name: string) => void; onCancel: () => void; }; export function InlineFileInput({ depth, onSubmit, onCancel }: InlineFileInputProps) { const inputRef = useRef(null); useEffect(() => { // Focus on next tick to ensure the element is rendered requestAnimationFrame(() => inputRef.current?.focus()); }, []); const handleKeyDown = useCallback( (e: React.KeyboardEvent) => { if (e.key === "Enter") { const value = inputRef.current?.value.trim(); if (value) onSubmit(value); else onCancel(); } else if (e.key === "Escape") { onCancel(); } }, [onSubmit, onCancel], ); const handleBlur = useCallback(() => { const value = inputRef.current?.value.trim(); if (value) onSubmit(value); else onCancel(); }, [onSubmit, onCancel]); return (
); }