Fix null handling

This commit is contained in:
Gert Hengeveld 2021-02-23 11:59:02 +01:00
parent c3e79d4c0a
commit e13c905ae5
2 changed files with 5 additions and 4 deletions

View File

@ -38,7 +38,8 @@ export const NumberControl: FC<NumberProps> = ({
onChange={handleChange}
size="flex"
placeholder="Adjust number dynamically"
{...{ name, value, min, max, step, onFocus, onBlur }}
value={value === null ? undefined : value}
{...{ name, min, max, step, onFocus, onBlur }}
/>
</Wrapper>
);

View File

@ -229,8 +229,8 @@ const getCustomStyleFunction: (theme: Theme) => JsonTreeProps['getStyle'] = (the
},
});
export const ObjectControl: React.FC<ObjectProps> = ({ name, value = {}, onChange }) => {
const data = useMemo(() => cloneDeep(value), [value]);
export const ObjectControl: React.FC<ObjectProps> = ({ name, value, onChange }) => {
const data = useMemo(() => value && cloneDeep(value), [value]);
const [showRaw, setShowRaw] = useState(false);
const [parseError, setParseError] = useState();
const updateRaw = useCallback(
@ -248,7 +248,7 @@ export const ObjectControl: React.FC<ObjectProps> = ({ name, value = {}, onChang
<RawInput
id={name}
name={name}
defaultValue={JSON.stringify(value, null, 2)}
defaultValue={value === null ? '' : JSON.stringify(value, null, 2)}
onBlur={(event) => updateRaw(event.target.value)}
placeholder="Enter JSON string"
valid={parseError ? 'error' : null}