Skip to content

Commit

Permalink
refactor(web/InventoryControl): floor input value and set minimum
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Oct 14, 2023
1 parent d6f89ee commit 103b1c6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions web/src/components/inventory/InventoryControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const InventoryControl: React.FC = () => {
}));

const inputHandler = (event: React.ChangeEvent<HTMLInputElement>) => {
if (event.target.valueAsNumber % 1 !== 0 || isNaN(event.target.valueAsNumber) || event.target.valueAsNumber < 0)
event.target.valueAsNumber = 0;
event.target.valueAsNumber =
isNaN(event.target.valueAsNumber) || event.target.valueAsNumber < 0 ? 0 : Math.floor(event.target.valueAsNumber);
dispatch(setItemAmount(event.target.valueAsNumber));
};

Expand All @@ -40,7 +40,13 @@ const InventoryControl: React.FC = () => {
<UsefulControls infoVisible={infoVisible} setInfoVisible={setInfoVisible} />
<div className="inventory-control">
<div className="inventory-control-wrapper">
<input className="inventory-control-input" type="number" defaultValue={itemAmount} onChange={inputHandler} />
<input
className="inventory-control-input"
type="number"
defaultValue={itemAmount}
onChange={inputHandler}
min={0}
/>
<button className="inventory-control-button" ref={use}>
{Locale.ui_use || 'Use'}
</button>
Expand Down

0 comments on commit 103b1c6

Please sign in to comment.