Skip to content

Commit

Permalink
feat : 모바일 뷰 입력할 때 화면 스크롤 방지
Browse files Browse the repository at this point in the history
  • Loading branch information
imeureka committed Oct 15, 2024
1 parent 07c7fcf commit b7c2abb
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/pages/Guest/Guest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { GUEST_KEYS } from '../../constants/QueryKey';

const Guest = () => {
const { data: guestBookData } = useGetGuestBookList();
console.log('실행', guestBookData);
const { GuestBookMutation } = usePostGuestBook();
const [isAnimating, setIsAnimating] = useState<boolean>(false);
const [isTyping, setIsTyping] = useState<boolean>(false);

const [formValues, setFormValues] = useState({
name: '',
Expand Down Expand Up @@ -46,14 +46,20 @@ const Guest = () => {

const handleInputChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
const { name, value } = e.target;
setIsTyping(true);
setFormValues((prevValues) => ({
...prevValues,
[name]: value,
}));
}, []);

const handleInputBlur = useCallback(() => {
setIsTyping(false);
}, []);
const scrollToBottom = () => {
entriesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
if (!isTyping) {
entriesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
}
};

const handleSubmit = async () => {
Expand Down Expand Up @@ -118,6 +124,7 @@ const Guest = () => {
type="text"
value={formValues.name}
onChange={handleInputChange}
onBlur={handleInputBlur}
placeholder="이름을 입력하세요"
autoComplete="off"
/>
Expand All @@ -126,6 +133,7 @@ const Guest = () => {
type="text"
value={formValues.comment}
onChange={handleInputChange}
onBlur={handleInputBlur}
placeholder="댓글을 입력하세요"
autoComplete="off"
/>
Expand Down

0 comments on commit b7c2abb

Please sign in to comment.