@@ -10,7 +10,7 @@ import {
1010import { BoolControl } from "comps/controls/boolControl" ;
1111import { dropdownControl } from "comps/controls/dropdownControl" ;
1212import { LabelControl } from "comps/controls/labelControl" ;
13- import { numberExposingStateControl } from "comps/controls/codeStateControl" ;
13+ import { numberExposingStateControl , stringExposingStateControl } from "comps/controls/codeStateControl" ;
1414import NP from "number-precision" ;
1515
1616import {
@@ -234,6 +234,7 @@ const UndefinedNumberControl = codeControl<number | undefined>((value: any) => {
234234} ) ;
235235
236236const childrenMap = {
237+ defaultValue : stringExposingStateControl ( "defaultValue" ) , // It is more convenient for string to handle various states, save raw input here
237238 value : numberExposingStateControl ( "value" ) , // It is more convenient for string to handle various states, save raw input here
238239 placeholder : StringControl ,
239240 disabled : BoolCodeControl ,
@@ -261,6 +262,17 @@ const childrenMap = {
261262
262263const CustomInputNumber = ( props : RecordConstructorToView < typeof childrenMap > ) => {
263264 const ref = useRef < HTMLInputElement | null > ( null ) ;
265+ const defaultValue = props . defaultValue . value ;
266+
267+ useEffect ( ( ) => {
268+ let value = 0 ;
269+ if ( defaultValue === 'null' && props . allowNull ) {
270+ value = NaN ;
271+ } else if ( ! isNaN ( Number ( defaultValue ) ) ) {
272+ value = Number ( defaultValue ) ;
273+ }
274+ props . value . onChange ( value ) ;
275+ } , [ defaultValue ] ) ;
264276
265277 const formatFn = ( value : number ) =>
266278 format ( value , props . allowNull , props . formatter , props . precision , props . thousandsSeparator ) ;
@@ -271,7 +283,9 @@ const CustomInputNumber = (props: RecordConstructorToView<typeof childrenMap>) =
271283 const oldValue = props . value . value ;
272284 const newValue = parseNumber ( tmpValue , props . allowNull ) ;
273285 props . value . onChange ( newValue ) ;
274- oldValue !== newValue && props . onEvent ( "change" ) ;
286+ if ( ( oldValue !== newValue ) ) {
287+ props . onEvent ( "change" ) ;
288+ }
275289 } ;
276290
277291 useEffect ( ( ) => {
@@ -363,7 +377,7 @@ const NumberInputTmpComp = (function () {
363377 . setPropertyViewFn ( ( children ) => (
364378 < >
365379 < Section name = { sectionNames . basic } >
366- { children . value . propertyView ( { label : trans ( "prop.defaultValue" ) } ) }
380+ { children . defaultValue . propertyView ( { label : trans ( "prop.defaultValue" ) } ) }
367381 { placeholderPropertyView ( children ) }
368382 { children . formatter . propertyView ( { label : trans ( "numberInput.formatter" ) } ) }
369383 </ Section >
0 commit comments