-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update handling of max-length property
- Loading branch information
Showing
3 changed files
with
31 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,23 @@ | ||
import { useRef } from 'react'; | ||
import { useState, type ChangeEvent } from 'react'; | ||
import { InputContainer, type IInputComponentProps } from '../inputContainer'; | ||
import { useInputProps } from '../useInputProps'; | ||
|
||
export interface IInputTextProps extends IInputComponentProps {} | ||
|
||
export const InputText: React.FC<IInputTextProps> = (props) => { | ||
const { containerProps, inputProps } = useInputProps(props); | ||
const { value, ...otherInputProps } = inputProps; | ||
const { value, onChange, ...otherInputProps } = inputProps; | ||
|
||
const inputRef = useRef<HTMLInputElement>(null); | ||
const inputLength = value?.toString().length ?? inputRef.current?.value.length; | ||
const [inputLength, setInputLength] = useState(0); | ||
|
||
console.log({ | ||
inputLength, | ||
valueLength: inputProps.value?.toString().length, | ||
refLength: inputRef.current?.value.length, | ||
}); | ||
const handleOnChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
setInputLength(event.target.value.length); | ||
onChange?.(event); | ||
}; | ||
|
||
return ( | ||
<InputContainer inputLength={inputLength} {...containerProps}> | ||
<input type="text" ref={inputRef} value={value} {...otherInputProps} /> | ||
<input type="text" value={value} onChange={handleOnChange} {...otherInputProps} /> | ||
</InputContainer> | ||
); | ||
}; |