Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/InputSwitch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const InputSwitch = (props: InputSwitchProps): JSX.Element => {
}
if (typeof value == "number") {
value = value * conversion;
value = Number(value.toFixed(4));
}
return value;
}, [getCurrentValue, id, min, conversion, dataType]);
Expand All @@ -67,6 +68,7 @@ const InputSwitch = (props: InputSwitchProps): JSX.Element => {
if (typeof value === "number") {
// Convert back to original units for updating recipe object
value = value / conversion;
value = Number(value.toFixed(4));
}
updateRecipeObj(selectedRecipeId, { [id]: value });
};
Expand All @@ -76,7 +78,8 @@ const InputSwitch = (props: InputSwitchProps): JSX.Element => {
const numericValue =
typeof value === "number" ? value : Number(value) || 0;
const step = dataType === "integer" ? 1 : 0.01;
const maxValue = (max ?? 1) * conversion;
let maxValue = (max ?? 1) * conversion;
maxValue = Number(maxValue.toFixed(4));

return (
<div className="input-switch">
Expand All @@ -100,6 +103,7 @@ const InputSwitch = (props: InputSwitchProps): JSX.Element => {
style={{ margin: "0 6px" }}
value={numericValue}
onChange={handleInputChange}
type="number"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type="number"
type="number"
tooltip={{ formatter: (value) => value?.toFixed(2) }}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line actually meant for the Slider, rather than the InputNumber?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the root of the issue here is that we're rounding off the values, but not the maxValues, so we're getting an issue where we're trying to allow the user to input the max of 0.16199999999, but then we round that to 0.162 which is above the max.

I'll add the same rounding to the maxValue and that will solve this issue!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix! just tested again and it worked well!

/>
{unit && <span>{unit}</span>}
</div>
Expand Down