File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change 1- import React , { useState , InputHTMLAttributes } from 'react' ;
1+ import React , { useState , InputHTMLAttributes , useEffect } from 'react' ;
22import uniqid from 'uniqid' ;
33
44import * as S from './styles' ;
@@ -30,6 +30,7 @@ export const Input = ({
3030} : InputProps ) => {
3131 const identifier = id || uniqid ( 'appetizer-input__' ) ;
3232 const [ active , setActive ] = useState ( ! ! props . placeholder ) ;
33+ const hasValue = ! ! props . value || ! ! props . defaultValue ;
3334
3435 const handleOnFocus = ( e : React . FocusEvent < HTMLInputElement > ) => {
3536 if ( onFocus ) onFocus ( e ) ;
@@ -41,6 +42,10 @@ export const Input = ({
4142 setActive ( e . target ?. value . length !== 0 || ! ! props . placeholder ) ;
4243 } ;
4344
45+ useEffect ( ( ) => {
46+ if ( hasValue ) setActive ( true ) ;
47+ } , [ hasValue ] ) ;
48+
4449 return (
4550 < S . Container >
4651 < S . InputContainer >
You can’t perform that action at this time.
0 commit comments