Skip to content

Commit

Permalink
Fix more broken empty value logic
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFarmer committed Mar 5, 2024
1 parent e5a9bda commit 43e2355
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/controls/NumericControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export const createNumericControl = (args: { coerceNumber: (value: number) => nu
const isLargeStepCount = stepCount && stepCount > maxStepsWithoutTextInput

const initialValue: number | undefined = typeof schema?.default === "number" ? schema.default : minimum
const value = data === undefined ? initialValue : data as number | null
const isEmptyObj = typeof data === "object" && data !== undefined && data !== null ? Object.keys(data as object).length === 0 : false
const value = data === undefined || isEmptyObj ? initialValue : data as number | null

const addonAfter = uischema.options?.addonAfter as string | undefined
const addonBefore = uischema.options?.addonBefore as string | undefined
Expand Down Expand Up @@ -79,15 +80,15 @@ export const createNumericControl = (args: { coerceNumber: (value: number) => nu
const tooltip = {
formatter: (value?: number) => {
if (isPercentage) {
return `${decimalToPercentage(value)}%`
return `${decimalToPercentage(value || initialValue)}%`
} else {
return `${addonBefore ? addonBefore : ""}${value || initialValue}${addonAfter ? addonAfter : ""}`
}
}
}

const slider = <Slider
value={value === null ? undefined : value}
value={value === null ? initialValue : value}
defaultValue={initialValue}
min={minimum}
max={maximum}
Expand Down

0 comments on commit 43e2355

Please sign in to comment.