Skip to content

Commit 9006747

Browse files
committed
♻️ refactor:navbar 크기 유짐 및 위치 유지
Issue Resolved: #
1 parent 7a089d2 commit 9006747

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

front/src/components/Navbar/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export default function Navbar() {
5454
const handleLogOut = () => {
5555
requestLogout();
5656
};
57-
//TODO 예약 내역
57+
5858
const isReservation = reservations && reservations.length > 0;
5959
const widthClass = `w-[${POPOVER_WIDTH}px]`;
6060
return (
@@ -77,7 +77,10 @@ export default function Navbar() {
7777
<Popover.Overlay>
7878
<Popover.Content>
7979
<div
80-
className={cx(widthClass, `flex flex-col gap-6 rounded-xl border bg-white p-6 shadow-2xl`)}>
80+
className={cx(
81+
widthClass,
82+
`flex max-h-[80vh] min-h-[300px] flex-col gap-6 rounded-xl border bg-white p-6 shadow-2xl`,
83+
)}>
8184
<h3 className="px-4 text-left text-heading3">예매 현황</h3>
8285
<Separator direction="row" />
8386
<div className="flex max-h-[800px] flex-col gap-6 overflow-y-scroll pr-4">

front/src/components/common/Popover.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import {
44
ReactElement,
55
ReactNode,
66
createContext,
7+
useCallback,
78
useContext,
9+
useEffect,
810
useRef,
911
useState,
1012
} from 'react';
@@ -87,10 +89,26 @@ interface IContent {
8789
}
8890
const Content = ({ children }: IContent) => {
8991
const { isOpen, triggerRef } = usePopoverContext();
92+
const [position, setPosition] = useState({ x: 0, y: 0 });
9093
const hasButtonRef = triggerRef && triggerRef.current;
9194
const canOpen = isOpen && hasButtonRef;
9295
//TODO 타입 정리필요, 상수 정리
93-
const { top, height } = triggerRef!.current!.getBoundingClientRect();
96+
const updatePosition = useCallback(() => {
97+
if (triggerRef && triggerRef.current) {
98+
const trigger = triggerRef.current!;
99+
const { top, height } = trigger.getBoundingClientRect();
100+
setPosition({ x: top, y: height });
101+
}
102+
}, [triggerRef]);
103+
104+
useEffect(() => {
105+
if (isOpen) {
106+
window.addEventListener('scroll', updatePosition);
107+
}
108+
return () => {
109+
window.removeEventListener('scroll', updatePosition);
110+
};
111+
}, [isOpen, updatePosition]);
94112

95113
return (
96114
<>
@@ -99,7 +117,7 @@ const Content = ({ children }: IContent) => {
99117
<div
100118
className="fixed z-[999] cursor-default"
101119
style={{
102-
top: top + height + 24,
120+
top: position.x + position.y + 24,
103121
right: 32,
104122
}}>
105123
{children}

0 commit comments

Comments
 (0)