/** * InlineSalePriceEditor Component * * Inline dropdown editor for sale price with date pickers * Full keyboard navigation support */ import React, { useState, useEffect, useRef } from 'react'; import { useTranslation } from 'react-i18next'; interface Props { currentPrice: string; dateFrom: string | null; dateTo: string | null; onSave: (price: string, dateFrom: string, dateTo: string) => void; onCancel: () => void; position: { top: number; left: number; width: number; showAbove: boolean }; } export default function InlineSalePriceEditor({ currentPrice, dateFrom, dateTo, onSave, onCancel, position }: Props) { const { t } = useTranslation(); const [price, setPrice] = useState(currentPrice || ''); const [from, setFrom] = useState(dateFrom || ''); const [to, setTo] = useState(dateTo || ''); const priceInputRef = useRef(null); const fromInputRef = useRef(null); const toInputRef = useRef(null); const containerRef = useRef(null); useEffect(() => { // Auto-focus price input with delay to prevent AG Grid from stealing focus const focusTimer = setTimeout(() => { if (priceInputRef.current) { priceInputRef.current.focus(); priceInputRef.current.select(); console.log('[InlineSalePriceEditor] Auto-focus + select applied'); } }, 50); // Small delay to let AG Grid settle // Click outside to close const handleClickOutside = (e: MouseEvent) => { if (containerRef.current && !containerRef.current.contains(e.target as Node)) { onCancel(); } }; document.addEventListener('mousedown', handleClickOutside); return () => { clearTimeout(focusTimer); document.removeEventListener('mousedown', handleClickOutside); }; }, [onCancel]); const handleKeyDown = (e: React.KeyboardEvent, field: 'price' | 'from' | 'to') => { if (e.key === 'Enter') { e.preventDefault(); // Tab navigation with Enter if (field === 'price' && fromInputRef.current) { fromInputRef.current.focus(); } else if (field === 'from' && toInputRef.current) { toInputRef.current.focus(); } else { // Save on final Enter handleSave(); } } else if (e.key === 'Escape') { e.preventDefault(); onCancel(); } else if (e.key === 'Tab') { // Allow natural tab navigation // Don't prevent default } }; const handleSave = () => { onSave(price, from, to); }; return ( <> {/* Backdrop overlay */}
{/* Inline dropdown editor */}
{/* Arrow pointing up or down */} {position.showAbove ? ( // Arrow pointing DOWN (when dropdown is above cell)
) : ( // Arrow pointing UP (when dropdown is below cell)
)}
{/* Header */}

{t('sale_price')}

{/* Price Input */}
setPrice(e.target.value.replace(/[^\d]/g, ''))} onKeyDown={(e) => handleKeyDown(e, 'price')} placeholder="0" className="w-full pl-3 pr-10 py-2.5 border-2 border-gray-300 rounded-lg focus:border-orange-500 focus:ring-2 focus:ring-orange-200 transition text-base font-mono font-semibold text-orange-600" /> Ft
{/* Date From */}
setFrom(e.target.value)} onKeyDown={(e) => handleKeyDown(e, 'from')} className="w-full px-3 py-2.5 border-2 border-gray-300 rounded-lg focus:border-indigo-500 focus:ring-2 focus:ring-indigo-200 transition text-sm" />
{/* Date To */}
setTo(e.target.value)} onKeyDown={(e) => handleKeyDown(e, 'to')} className="w-full px-3 py-2.5 border-2 border-gray-300 rounded-lg focus:border-indigo-500 focus:ring-2 focus:ring-indigo-200 transition text-sm" />
{/* Actions */}
{/* Keyboard hints */}

💡 Enter = {t('editor.next_field')} · Esc = {t('common.cancel')}

); }