Skip to content

Commit 6785763

Browse files
authored
Merge pull request #27 from getinapp/fix/input-label-position
[BUGFIX] - Input label position
2 parents 50c53f4 + af07cfd commit 6785763

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/components/Input/index.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, InputHTMLAttributes } from 'react';
1+
import React, { useState, InputHTMLAttributes, useEffect } from 'react';
22
import uniqid from 'uniqid';
33

44
import * 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>

src/styles/global.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const GlobalStyles = createGlobalStyle`
3838
::-webkit-scrollbar {
3939
width: 0;
4040
}
41+
4142
::-webkit-scrollbar-track {
4243
background: transparent;
4344
}
@@ -55,9 +56,8 @@ const GlobalStyles = createGlobalStyle`
5556
`}
5657
5758
.ReactModal__Overlay {
58-
opacity: 0;
59-
transition: opacity 500ms ease-in-out;
60-
}
59+
opacity: 0;
60+
transition: opacity 500ms ease-in-out;
6161
6262
.ReactModal__Overlay--after-open {
6363
opacity: 1;
@@ -76,8 +76,6 @@ const GlobalStyles = createGlobalStyle`
7676
bottom: 0;
7777
background-color: rgba(0,0,0,0.5);
7878
}
79-
80-
8179
`;
8280

8381
export default GlobalStyles;

0 commit comments

Comments
 (0)