@@ -42,38 +42,38 @@ export const NumberControl: FC<NumberProps> = ({
4242 const readonly = ! ! argType ?. table ?. readonly ;
4343
4444 const handleChange = useCallback (
45- ( event : ChangeEvent < HTMLInputElement > ) => {
46- setInputValue ( event . target . value ) ;
47-
48- const result = parseFloat ( event . target . value ) ;
49- if ( Number . isNaN ( result ) ) {
50- setParseError ( new Error ( `'${ event . target . value } ' is not a number` ) ) ;
51- } else {
52- // Initialize the final value as the user's input
53- let finalValue = result ;
54-
55- // Clamp to minimum: if finalValue is less than min, use min
56- if ( typeof min === 'number' && finalValue < min ) {
57- finalValue = min ;
58- }
59-
60- // Clamp to maximum: if finalValue is greater than max, use max
61- if ( typeof max === 'number' && finalValue > max ) {
62- finalValue = max ;
63- }
64-
65- // Pass the clamped final value to the onChange callback
66- onChange ( finalValue ) ;
67- // Clear any previous parse errors
68- setParseError ( null ) ;
69-
70- // If the value was clamped, update the input display to the final value
71- if ( finalValue !== result ) {
72- setInputValue ( String ( finalValue ) ) ;
73- }
74- }
75- } ,
76- [ onChange , setParseError , min , max ]
45+ ( event : ChangeEvent < HTMLInputElement > ) => {
46+ setInputValue ( event . target . value ) ;
47+
48+ const result = parseFloat ( event . target . value ) ;
49+ if ( Number . isNaN ( result ) ) {
50+ setParseError ( new Error ( `'${ event . target . value } ' is not a number` ) ) ;
51+ } else {
52+ // Initialize the final value as the user's input
53+ let finalValue = result ;
54+
55+ // Clamp to minimum: if finalValue is less than min, use min
56+ if ( typeof min === 'number' && finalValue < min ) {
57+ finalValue = min ;
58+ }
59+
60+ // Clamp to maximum: if finalValue is greater than max, use max
61+ if ( typeof max === 'number' && finalValue > max ) {
62+ finalValue = max ;
63+ }
64+
65+ // Pass the clamped final value to the onChange callback
66+ onChange ( finalValue ) ;
67+ // Clear any previous parse errors
68+ setParseError ( null ) ;
69+
70+ // If the value was clamped, update the input display to the final value
71+ if ( finalValue !== result ) {
72+ setInputValue ( String ( finalValue ) ) ;
73+ }
74+ }
75+ } ,
76+ [ onChange , setParseError , min , max ]
7777 ) ;
7878
7979 const onForceVisible = useCallback ( ( ) => {
0 commit comments