Bug fixes
This commit is contained in:
@@ -12,6 +12,11 @@ import { usePrefersReducedMotion } from "@/hooks/use-prefers-reduced-motion";
|
||||
const randInt = (lo: number, hi: number) =>
|
||||
lo + Math.floor(Math.random() * (hi - lo + 1));
|
||||
|
||||
const toInt = (raw: string) => {
|
||||
const n = Math.round(Number(raw));
|
||||
return Number.isFinite(n) ? n : 0;
|
||||
};
|
||||
|
||||
export default function RandomNumber() {
|
||||
const [min, setMin] = useLocalStorage("num-min", 1);
|
||||
const [max, setMax] = useLocalStorage("num-max", 100);
|
||||
@@ -120,9 +125,11 @@ export default function RandomNumber() {
|
||||
</span>
|
||||
<input
|
||||
type="number"
|
||||
step={1}
|
||||
value={min}
|
||||
onChange={(e) => setMin(Number(e.target.value))}
|
||||
className="tabular w-full rounded-xl border border-line bg-surface px-3.5 py-2.5 text-sm font-medium outline-none transition focus:border-primary/60 focus:ring-2 focus:ring-primary/20"
|
||||
onChange={(e) => setMin(toInt(e.target.value))}
|
||||
disabled={rolling}
|
||||
className="tabular w-full rounded-xl border border-line bg-surface px-3.5 py-2.5 text-sm font-medium outline-none transition focus:border-primary/60 focus:ring-2 focus:ring-primary/20 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
/>
|
||||
</label>
|
||||
<label className="block">
|
||||
@@ -131,9 +138,11 @@ export default function RandomNumber() {
|
||||
</span>
|
||||
<input
|
||||
type="number"
|
||||
step={1}
|
||||
value={max}
|
||||
onChange={(e) => setMax(Number(e.target.value))}
|
||||
className="tabular w-full rounded-xl border border-line bg-surface px-3.5 py-2.5 text-sm font-medium outline-none transition focus:border-primary/60 focus:ring-2 focus:ring-primary/20"
|
||||
onChange={(e) => setMax(toInt(e.target.value))}
|
||||
disabled={rolling}
|
||||
className="tabular w-full rounded-xl border border-line bg-surface px-3.5 py-2.5 text-sm font-medium outline-none transition focus:border-primary/60 focus:ring-2 focus:ring-primary/20 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user