-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
검색창 및 드롭다운 Blur 이벤트 추가
- Loading branch information
Showing
7 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
.search-bar__dropdown { | ||
text-align: left; | ||
background-color: white !important; | ||
position: absolute; | ||
top: 6.4rem; | ||
padding: 1rem; | ||
margin-right: 2.6rem; | ||
white-space: wrap; | ||
} | ||
|
||
@media screen and (max-width: 1200px) { | ||
.search-bar__dropdown { | ||
top: 5.5rem; | ||
} | ||
} | ||
|
||
@media screen and (max-width: 767px) { | ||
.search-bar__dropdown { | ||
top: 5rem; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const BookSearchPreview = () => { | ||
return <div>결과 미리보기</div>; | ||
}; | ||
|
||
export default BookSearchPreview; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const BookSearchRecentKeyword = () => { | ||
return <div>최근 검색어</div>; | ||
}; | ||
|
||
export default BookSearchRecentKeyword; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { | ||
Dispatch, | ||
ReactNode, | ||
RefObject, | ||
SetStateAction, | ||
useEffect, | ||
useRef, | ||
} from "react"; | ||
import "~/asset/css/SearchBarDropdown.css"; | ||
|
||
type Props = { | ||
isOpened: boolean; | ||
setIsOpened: Dispatch<SetStateAction<boolean>>; | ||
searchBarRef: RefObject<HTMLInputElement>; | ||
children: ReactNode; | ||
}; | ||
const SearchBarDropDown = ({ | ||
isOpened, | ||
setIsOpened, | ||
searchBarRef, | ||
children, | ||
}: Props) => { | ||
const dropDownRef = useRef<HTMLDivElement>(null); | ||
|
||
useEffect(() => { | ||
const closeWhenClickedOutside = (e: MouseEvent) => { | ||
if ( | ||
searchBarRef.current && | ||
dropDownRef.current && | ||
!searchBarRef.current.contains(e.target as Node) && | ||
!dropDownRef.current.contains(e.target as Node) | ||
) | ||
setIsOpened(false); | ||
}; | ||
document.addEventListener("click", closeWhenClickedOutside); | ||
return () => { | ||
document.removeEventListener("click", closeWhenClickedOutside); | ||
}; | ||
}, []); | ||
|
||
if (isOpened) | ||
return ( | ||
<div ref={dropDownRef} className="search-bar__dropdown"> | ||
{children} | ||
</div> | ||
); | ||
return null; | ||
}; | ||
|
||
export default SearchBarDropDown; |