From f63d40196d133155cfcd80f5049bd1f1f256c5dc Mon Sep 17 00:00:00 2001 From: k00b Date: Tue, 22 Jul 2025 18:26:29 -0500 Subject: [PATCH] fix variable input icon alignment --- components/adv-post-form.js | 3 +- components/form.js | 124 ++++++++++++++++++++---------------- 2 files changed, 70 insertions(+), 57 deletions(-) diff --git a/components/adv-post-form.js b/components/adv-post-form.js index 51ade562..d73a2885 100644 --- a/components/adv-post-form.js +++ b/components/adv-post-form.js @@ -269,7 +269,7 @@ export default function AdvPostForm ({ children, item, sub, storageKeyPrefix }) emptyItem={EMPTY_FORWARD} hint={Forward sats to up to 5 other stackers. Any remaining sats go to you.} > - {({ index, placeholder }) => { + {({ index, AppendColumn }) => { return (
%} groupClassName={`${styles.percent} mb-0`} + AppendColumn={AppendColumn} />
) diff --git a/components/form.js b/components/form.js index 852c24f8..1d9e150d 100644 --- a/components/form.js +++ b/components/form.js @@ -609,7 +609,7 @@ function FormGroup ({ className, label, children }) { function InputInner ({ prepend, append, hint, warn, showValid, onChange, onBlur, overrideValue, appendValue, innerRef, noForm, clear, onKeyDown, inputGroupClassName, debounce: debounceTime, maxLength, hideError, - ...props + AppendColumn, ...props }) { const [field, meta, helpers] = noForm ? [{}, {}, {}] : useField(props) const formik = noForm ? null : useFormikContext() @@ -687,38 +687,43 @@ function InputInner ({ return ( <> - - {prepend} - - {(isClient && clear && field.value && !props.readOnly) && - } - {append} - - {meta.touched && meta.error} - - + + + + {prepend} + + {(isClient && clear && field.value && !props.readOnly) && + } + {append} + + {meta.touched && meta.error} + + + + {AppendColumn && } + {hint && ( {hint} @@ -952,31 +957,38 @@ export function VariableInput ({ label, groupClassName, name, hint, max, min, re {({ form, ...fieldArrayHelpers }) => { const options = form.values[name] + return ( <> - {options?.map((_, i) => ( -
- - - {children - ? children({ index: i, readOnly: i < readOnlyLen, placeholder: i >= min ? 'optional' : undefined }) - : = min ? 'optional' : undefined} />} - - - {options.length - 1 === i && options.length !== max - ? fieldArrayHelpers.push(emptyItem)} /> - // filler div for col alignment across rows - :
} - - {options.length - 1 === i && - <> - {hint && {hint}} - {form.touched[name] && typeof form.errors[name] === 'string' && -
{form.errors[name]}
} - } - -
- ))} + {options?.map((_, i) => { + const AppendColumn = ({ className }) => ( + + {options.length - 1 === i && options.length !== max + // onMouseDown is used to prevent the blur event on text inputs from overriding the click event + ? fieldArrayHelpers.push(emptyItem)} /> + // filler div for col alignment across rows + :
} + + ) + return ( +
+ + + {children + ? children({ index: i, readOnly: i < readOnlyLen, placeholder: i >= min ? 'optional' : undefined, AppendColumn }) + : = min ? 'optional' : undefined} AppendColumn={AppendColumn} />} + + + {options.length - 1 === i && + <> + {hint && {hint}} + {form.touched[name] && typeof form.errors[name] === 'string' && +
{form.errors[name]}
} + } +
+
+ ) + })} ) }}