diff --git a/src/components/AmountEditable.tsx b/src/components/AmountEditable.tsx index b56a5b7..2cd53c4 100644 --- a/src/components/AmountEditable.tsx +++ b/src/components/AmountEditable.tsx @@ -161,7 +161,6 @@ export const AmountEditable: ParentComponent<{ const isFiatMode = mode() === "fiat"; const inputSanitizer = isFiatMode ? fiatInputSanitizer : satsInputSanitizer; const localValue = isFiatMode ? localFiat : localSats; - const inputRef = isFiatMode ? fiatInputRef : satsInputRef; let sane; @@ -184,7 +183,7 @@ export const AmountEditable: ParentComponent<{ } // After a button press make sure we re-focus the input - inputRef.focus(); + focus(); } function setFixedAmount(amount: string) { @@ -220,17 +219,24 @@ export const AmountEditable: ParentComponent<{ function toggle() { setMode((m) => (m === "sats" ? "fiat" : "sats")); - if (mode() === "sats") { - satsInputRef.focus(); - } else { - fiatInputRef.focus(); - } + focus(); } onMount(() => { - satsInputRef.focus(); + focus(); }); + function focus() { + // Make sure we actually have the inputs mounted before we try to focus them + if (isOpen() && satsInputRef && fiatInputRef) { + if (mode() === "sats") { + satsInputRef.focus(); + } else { + fiatInputRef.focus(); + } + } + } + return (