diff --git a/src/components/CardList/index.jsx b/src/components/CardList/index.jsx index 50cca7d..be49e57 100644 --- a/src/components/CardList/index.jsx +++ b/src/components/CardList/index.jsx @@ -21,6 +21,8 @@ const CardList = ({ cards, pageWidth }) => { Navigate(`/post/${id}`); }; + const btnHoverAnimation = 'hover:transform hover:translate-y-[-5px] transition-transform duration-300 ease-in-out'; + return (
{cards.map((item, i) => { @@ -30,7 +32,7 @@ const CardList = ({ cards, pageWidth }) => {
cardMove(item.id)} role='presentation' - className={`flex flex-col justify-between border rounded-2xl border-gray-40 bg-gray-10 px-4 py-4 cursor-pointer ${DISPLAY_CLASS_NAME}`} + className={`flex flex-col justify-between border rounded-2xl border-gray-40 bg-gray-10 px-4 py-4 cursor-pointer ${DISPLAY_CLASS_NAME} ${btnHoverAnimation} hover:border-gray-50`} key={item.id} >
diff --git a/src/components/SortDropDown/index.jsx b/src/components/SortDropDown/index.jsx index 1a436cb..8c5e39d 100644 --- a/src/components/SortDropDown/index.jsx +++ b/src/components/SortDropDown/index.jsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useRef, useState, useEffect } from 'react'; import PropTypes from 'prop-types'; import DropDonwUpImg from 'assets/images/icons/ic_Arrow-up.svg'; import { ReactComponent as DropDownUnderImg } from 'assets/images/icons/ic_Arrow-down.svg'; @@ -11,7 +11,10 @@ const SortDropDown = ({ changeSort }) => { const [sortText, setSortText] = useState('최신순'); - const toggleDropdown = () => { + const dropdownRef = useRef(null); + + const toggleDropdown = (e) => { + e.stopPropagation(); setIsOpen((prevState) => !prevState); }; @@ -22,18 +25,33 @@ const SortDropDown = ({ changeSort }) => { changeSort(target.textContent); }; + // 외부 클릭 시 드롭다운을 닫는 함수 + const handleClickOutside = (event) => { + if (dropdownRef.current && !dropdownRef.current.contains(event.target)) { + setIsOpen(false); + } + }; + + // 컴포넌트 마운트 시 이벤트 리스너 추가 + useEffect(() => { + document.addEventListener('click', handleClickOutside); + return () => { + document.removeEventListener('click', handleClickOutside); + }; + }, []); + return ( -
+
{isOpen && ( -
    -
  • +
      +
    • 이름순
    • -
    • +
    • 최신순
    diff --git a/src/pages/QuestionList/index.jsx b/src/pages/QuestionList/index.jsx index 1f38535..0f25638 100644 --- a/src/pages/QuestionList/index.jsx +++ b/src/pages/QuestionList/index.jsx @@ -54,7 +54,7 @@ const QuestionList = () => {