Skip to content

Commit

Permalink
enter키로 로그인 구현
Browse files Browse the repository at this point in the history
enter키로 로그인 구현
  • Loading branch information
phyuna0525 authored Mar 16, 2024
2 parents 68ece50 + 9efa34e commit 00ae1da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/app/components/common/input/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";
import { useState } from "react";

import React, { useState } from "react";
import Image from "next/image";
import eye from "../../../../assets/img/Icon/eye.svg";
import eyeOff from "../../../../assets/img/Icon/eyeOff.svg";
Expand All @@ -19,6 +20,7 @@ interface InputProps {
onChange: ({ text, name }: ChangeProps) => void;
disabled?: boolean;
value: string;
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement>) => void;
}

const Input: React.FC<InputProps> = ({
Expand All @@ -30,6 +32,7 @@ const Input: React.FC<InputProps> = ({
disabled,
value,
error,
onKeyDown,
name = "",
}) => {
const [showOpen, setShowOpen] = useState<boolean>(false);
Expand All @@ -44,7 +47,7 @@ const Input: React.FC<InputProps> = ({
}
`;

const inputClassName = ` h-10 px-2 border-none bg-transparent placeholder-neutral-500
const inputClassName = ` h-10 w-full px-2 border-none bg-transparent placeholder-neutral-500
focus:outline-none rounded font-sans
`;

Expand All @@ -59,6 +62,7 @@ const Input: React.FC<InputProps> = ({
value={value}
onChange={(e) => onChange({ text: e.target.value, name })}
disabled={disabled}
onKeyDown={onKeyDown}
/>
{type === "password" && (
<div onClick={() => setShowOpen(!showOpen)} className="">
Expand Down
9 changes: 8 additions & 1 deletion src/app/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ const Login: NextPage = () => {
const handleChange = ({ text, name }: ChangeProps) => {
setData({ ...data, [name]: text });
};
const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
if (event.key === "Enter") {
onClickBtn();
}
};

const { mutate: loginMutate } = useLogin();
const router = useRouter();
Expand All @@ -50,7 +55,7 @@ const Login: NextPage = () => {
});
} catch (error) {
console.error("An unexpected error occurred:", error);
router.push("/login");
router.push("/login");
}
};

Expand All @@ -76,6 +81,7 @@ const Login: NextPage = () => {
placeholder="아이디"
onChange={handleChange}
value={data.admin_id}
onKeyDown={handleKeyDown}
name="admin_id"
/>
<div className="flex flex-col gap-6">
Expand All @@ -85,6 +91,7 @@ const Login: NextPage = () => {
label="비밀번호"
placeholder="비밀번호"
onChange={handleChange}
onKeyDown={handleKeyDown}
name="password"
value={data.password}
/>
Expand Down

0 comments on commit 00ae1da

Please sign in to comment.