@@ -10,7 +10,7 @@ import {
10
10
import { BoolControl } from "comps/controls/boolControl" ;
11
11
import { dropdownControl } from "comps/controls/dropdownControl" ;
12
12
import { LabelControl } from "comps/controls/labelControl" ;
13
- import { numberExposingStateControl } from "comps/controls/codeStateControl" ;
13
+ import { numberExposingStateControl , stringExposingStateControl } from "comps/controls/codeStateControl" ;
14
14
import NP from "number-precision" ;
15
15
16
16
import {
@@ -234,6 +234,7 @@ const UndefinedNumberControl = codeControl<number | undefined>((value: any) => {
234
234
} ) ;
235
235
236
236
const childrenMap = {
237
+ defaultValue : stringExposingStateControl ( "defaultValue" ) , // It is more convenient for string to handle various states, save raw input here
237
238
value : numberExposingStateControl ( "value" ) , // It is more convenient for string to handle various states, save raw input here
238
239
placeholder : StringControl ,
239
240
disabled : BoolCodeControl ,
@@ -261,6 +262,17 @@ const childrenMap = {
261
262
262
263
const CustomInputNumber = ( props : RecordConstructorToView < typeof childrenMap > ) => {
263
264
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 ] ) ;
264
276
265
277
const formatFn = ( value : number ) =>
266
278
format ( value , props . allowNull , props . formatter , props . precision , props . thousandsSeparator ) ;
@@ -271,7 +283,9 @@ const CustomInputNumber = (props: RecordConstructorToView<typeof childrenMap>) =
271
283
const oldValue = props . value . value ;
272
284
const newValue = parseNumber ( tmpValue , props . allowNull ) ;
273
285
props . value . onChange ( newValue ) ;
274
- oldValue !== newValue && props . onEvent ( "change" ) ;
286
+ if ( ( oldValue !== newValue ) ) {
287
+ props . onEvent ( "change" ) ;
288
+ }
275
289
} ;
276
290
277
291
useEffect ( ( ) => {
@@ -363,7 +377,7 @@ const NumberInputTmpComp = (function () {
363
377
. setPropertyViewFn ( ( children ) => (
364
378
< >
365
379
< Section name = { sectionNames . basic } >
366
- { children . value . propertyView ( { label : trans ( "prop.defaultValue" ) } ) }
380
+ { children . defaultValue . propertyView ( { label : trans ( "prop.defaultValue" ) } ) }
367
381
{ placeholderPropertyView ( children ) }
368
382
{ children . formatter . propertyView ( { label : trans ( "numberInput.formatter" ) } ) }
369
383
</ Section >
0 commit comments