mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-08-24 23:32:19 +10:00
fix: address review feedback for margin input clamping
Move clamp helpers above PageSectionForm for consistent scope/indentation, and only persist finite numeric values so empty or invalid input cannot enter resume metadata. Co-authored-by: Amruth Pillai <im.amruth@gmail.com>
This commit is contained in:
co-authored by
Amruth Pillai
parent
3e2c991344
commit
f55e584e34
@@ -29,6 +29,11 @@ const formSchema = pageSchema;
|
|||||||
|
|
||||||
type FormValues = z.infer<typeof formSchema>;
|
type FormValues = z.infer<typeof formSchema>;
|
||||||
|
|
||||||
|
const CLAMP_MIN = 0;
|
||||||
|
const CLAMP_MAX = 100;
|
||||||
|
|
||||||
|
const clamp = (value: number, min: number, max: number) => Math.min(Math.max(value, min), max);
|
||||||
|
|
||||||
function PageSectionForm() {
|
function PageSectionForm() {
|
||||||
const resume = useResume();
|
const resume = useResume();
|
||||||
const page = resume?.data.metadata.page;
|
const page = resume?.data.metadata.page;
|
||||||
@@ -53,12 +58,7 @@ function PageSectionForm() {
|
|||||||
persist({ ...form.state.values, [name]: value });
|
persist({ ...form.state.values, [name]: value });
|
||||||
};
|
};
|
||||||
|
|
||||||
const CLAMP_MIN = 0;
|
const pageNumberFields = [
|
||||||
const CLAMP_MAX = 100;
|
|
||||||
|
|
||||||
const clamp = (value: number, min: number, max: number) => Math.min(Math.max(value, min), max);
|
|
||||||
|
|
||||||
const pageNumberFields = [
|
|
||||||
{ name: "marginX" as const, label: <Trans>Margin (Horizontal)</Trans>, min: CLAMP_MIN, max: CLAMP_MAX },
|
{ name: "marginX" as const, label: <Trans>Margin (Horizontal)</Trans>, min: CLAMP_MIN, max: CLAMP_MAX },
|
||||||
{ name: "marginY" as const, label: <Trans>Margin (Vertical)</Trans>, min: CLAMP_MIN, max: CLAMP_MAX },
|
{ name: "marginY" as const, label: <Trans>Margin (Vertical)</Trans>, min: CLAMP_MIN, max: CLAMP_MAX },
|
||||||
{ name: "gapX" as const, label: <Trans>Spacing (Horizontal)</Trans>, min: 0, max: undefined },
|
{ name: "gapX" as const, label: <Trans>Spacing (Horizontal)</Trans>, min: 0, max: undefined },
|
||||||
@@ -156,8 +156,13 @@ const pageNumberFields = [
|
|||||||
onBlur={field.handleBlur}
|
onBlur={field.handleBlur}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
const v = e.target.value;
|
const v = e.target.value;
|
||||||
const raw = v === "" ? ("" as unknown as number) : Number(v);
|
// Ignore transient empty/invalid input so resume metadata stays numeric
|
||||||
const num = max !== undefined && typeof raw === "number" ? clamp(raw, min ?? 0, max) : raw;
|
if (v === "") return;
|
||||||
|
|
||||||
|
const raw = Number(v);
|
||||||
|
if (!Number.isFinite(raw)) return;
|
||||||
|
|
||||||
|
const num = max !== undefined ? clamp(raw, min ?? 0, max) : Math.max(raw, min ?? 0);
|
||||||
field.handleChange(num);
|
field.handleChange(num);
|
||||||
handleAutoSave(name, num);
|
handleAutoSave(name, num);
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user