feat(numberWidget): auto convert non-number value to number

This commit is contained in:
Bowen Tan 2022-08-01 18:27:21 +08:00
parent 2e1f012698
commit efe6865ecc

View File

@ -1,4 +1,4 @@
import React, { useRef } from 'react';
import React, { useEffect, useRef } from 'react';
import { WidgetProps } from '../../types/widget';
import { implementWidget } from '../../utils/widget';
import {
@ -23,6 +23,15 @@ export const NumberField: React.FC<WidgetProps<NumberFieldType>> = props => {
const [stringValue, setStringValue] = React.useState(String(value));
const numValue = useRef<number>(value);
useEffect(() => {
// Convert value to boolean after switch from expression widget mode.
if (typeof value !== 'number') {
onChange(0);
setStringValue('0');
numValue.current = 0;
}
}, [onChange, value]);
return (
<NumberInput
value={stringValue}