11import { pick } from 'ramda' ;
22import React , {
3+ InputHTMLAttributes ,
34 KeyboardEvent ,
45 KeyboardEventHandler ,
56 useCallback ,
67 useEffect ,
78 useRef ,
89 useState ,
9- useId ,
1010} from 'react' ;
11+ import uniqid from 'uniqid' ;
1112import fastIsNumeric from 'fast-isnumeric' ;
1213import LoadingElement from '../utils/_LoadingElement' ;
1314import './css/input.css' ;
@@ -260,7 +261,7 @@ type InputProps = {
260261 type ?: HTMLInputTypes ;
261262} ;
262263
263- const inputProps : ( keyof InputProps ) [ ] = [
264+ const inputProps = [
264265 'type' ,
265266 'placeholder' ,
266267 'inputMode' ,
@@ -279,7 +280,12 @@ const inputProps: (keyof InputProps)[] = [
279280 'maxLength' ,
280281 'pattern' ,
281282 'size' ,
282- ] ;
283+ ] as const ;
284+
285+ type HTMLInputProps = Extract <
286+ ( typeof inputProps ) [ number ] ,
287+ keyof InputHTMLAttributes < HTMLInputElement >
288+ > ;
283289
284290const defaultProps : Partial < InputProps > = {
285291 type : HTMLInputTypes . text ,
@@ -330,7 +336,7 @@ function Input({
330336 const input = useRef ( document . createElement ( 'input' ) ) ;
331337 const [ value , setValue ] = useState < InputProps [ 'value' ] > ( props . value ) ;
332338 const [ pendingEvent , setPendingEvent ] = useState < number > ( ) ;
333- const inputId = useId ( ) ;
339+ const inputId = useState ( ( ) => uniqid ( 'input-' ) ) [ 0 ] ;
334340
335341 const valprops =
336342 props . type === HTMLInputTypes . number ? { } : { value : value ?? '' } ;
@@ -401,7 +407,11 @@ function Input({
401407 value = convert ( value ) ;
402408
403409 if ( ! isEquivalent ( base , value ) ) {
404- input . current . value = `${ value } ` ?? '' ;
410+ if ( typeof value === 'undefined' ) {
411+ input . current . value = '' ;
412+ } else {
413+ input . current . value = `${ value } ` ;
414+ }
405415 }
406416 } ,
407417 [ ]
@@ -490,7 +500,10 @@ function Input({
490500 }
491501 } , [ value , props . debounce , props . type ] ) ;
492502
493- const pickedInputs = pick ( inputProps , props ) ;
503+ const pickedInputs = pick ( inputProps , props ) as Pick <
504+ InputHTMLAttributes < HTMLInputElement > ,
505+ HTMLInputProps
506+ > ;
494507
495508 const isNumberInput = props . type === HTMLInputTypes . number ;
496509 const currentNumericValue = convert ( input . current . value || '0' ) ;
0 commit comments