diff --git a/frontend/src/components/domain/unified-wizard/UnifiedAddWizard.tsx b/frontend/src/components/domain/unified-wizard/UnifiedAddWizard.tsx index 5ec04d0f..15ae7fb7 100644 --- a/frontend/src/components/domain/unified-wizard/UnifiedAddWizard.tsx +++ b/frontend/src/components/domain/unified-wizard/UnifiedAddWizard.tsx @@ -1,4 +1,4 @@ -import React, { useState, useCallback } from 'react'; +import React, { useState, useCallback, useMemo } from 'react'; import { Sparkles } from 'lucide-react'; import { WizardModal, WizardStep } from '../../ui/WizardModal/WizardModal'; import { ItemTypeSelector, ItemType } from './ItemTypeSelector'; @@ -57,7 +57,9 @@ export const UnifiedAddWizard: React.FC = ({ ); // Get wizard steps based on selected item type - const getWizardSteps = (): WizardStep[] => { + // CRITICAL: Memoize the steps to prevent component recreation on every render + // Without this, every keystroke causes the component to unmount/remount, losing focus + const wizardSteps = useMemo((): WizardStep[] => { if (!selectedItemType) { // Step 0: Item Type Selection return [ @@ -95,7 +97,7 @@ export const UnifiedAddWizard: React.FC = ({ default: return []; } - }; + }, [selectedItemType, handleItemTypeSelect]); // Only recreate when item type changes, NOT when wizardData changes // Get wizard title based on selected item type const getWizardTitle = (): string => { @@ -124,7 +126,7 @@ export const UnifiedAddWizard: React.FC = ({ onClose={handleClose} onComplete={handleWizardComplete} title={getWizardTitle()} - steps={getWizardSteps()} + steps={wizardSteps} icon={} size="xl" />