Skip to content

Commit

Permalink
LF-4618: Use reset value
Browse files Browse the repository at this point in the history
  • Loading branch information
Tbrid committed Jan 20, 2025
1 parent 3fbbf5d commit 2ed9bd0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/webapp/src/components/Form/NumberInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default function NumberInput<T extends FieldValues>({
}: NumberInputProps<T>) {
const { field, fieldState, formState } = useController({ name, control, rules, defaultValue });
const { inputProps, reset, numericValue, increment, decrement } = useNumberInput({
initialValue: defaultValue || field.value || get(formState.defaultValues, name),
initialValue: field.value || get(formState.defaultValues, name) || defaultValue,
allowDecimal,
decimalDigits,
locale,
Expand All @@ -86,7 +86,7 @@ export default function NumberInput<T extends FieldValues>({
{...inputProps}
className={className}
error={fieldState.error?.message}
onResetIconClick={reset}
onResetIconClick={() => reset(defaultValue)}
leftSection={currencySymbol}
rightSection={
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export default function useNumberInput({
const stepDecimalPlaces = countDecimalPlaces(step);
const options: Intl.NumberFormatOptions = {
useGrouping,
minimumFractionDigits: !allowDecimal ? undefined : decimalDigits ?? stepDecimalPlaces,
maximumFractionDigits: !allowDecimal ? 0 : decimalDigits ?? (stepDecimalPlaces || 20),
minimumFractionDigits: !allowDecimal ? undefined : (decimalDigits ?? stepDecimalPlaces),
maximumFractionDigits: !allowDecimal ? 0 : (decimalDigits ?? (stepDecimalPlaces || 20)),
};

return createNumberFormatter(locale, options);
Expand Down Expand Up @@ -199,7 +199,7 @@ export default function useNumberInput({
return {
numericValue,
inputProps,
reset: () => update(initialValue ?? NaN),
reset: (value?: number | null) => update(value ? value : NaN),
clear: () => update(NaN),
update,
increment,
Expand Down

0 comments on commit 2ed9bd0

Please sign in to comment.