Skip to content

Commit

Permalink
fix: esc를 누르거나, 옵션창 외부 클릭시 옵션창 사라지도록 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
pipisebastian committed Nov 28, 2024
1 parent 67ca5da commit 16cffe8
Showing 1 changed file with 44 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export const TypeOptionModal = ({
case "Enter":
e.preventDefault();
onTypeSelect(options[selectedIndex].id);

onClose();
break;

Expand All @@ -60,35 +59,50 @@ export const TypeOptionModal = ({
if (!isOpen) return null;

return createPortal(
<motion.div
ref={modalRef}
tabIndex={0}
className={optionModal}
style={{
left: `${position.left}px`,
top: `${position.top}px`,
outline: "none",
}}
initial={modal.initial}
animate={modal.animate}
onKeyDown={handleKeyDown}
>
<div className={modalContainer}>
{options.map((option, index) => (
<button
key={option.id}
className={`${optionTypeButton} ${index === selectedIndex && "selected"}`}
onClick={() => {
onTypeSelect(option.id);
onClose();
}}
onMouseEnter={() => setSelectedIndex(index)}
>
{option.label}
</button>
))}
</div>
</motion.div>,
<>
<div
style={{
position: "fixed",
top: 0,
left: 0,
right: 0,
bottom: 0,
background: "transparent",
zIndex: 999,
}}
onClick={onClose}
/>
<motion.div
ref={modalRef}
tabIndex={0}
className={optionModal}
style={{
left: `${position.left}px`,
top: `${position.top}px`,
outline: "none",
zIndex: 1000,
}}
initial={modal.initial}
animate={modal.animate}
onKeyDown={handleKeyDown}
>
<div className={modalContainer}>
{options.map((option, index) => (
<button
key={option.id}
className={`${optionTypeButton} ${index === selectedIndex && "selected"}`}
onClick={() => {
onTypeSelect(option.id);
onClose();
}}
onMouseEnter={() => setSelectedIndex(index)}
>
{option.label}
</button>
))}
</div>
</motion.div>
</>,
document.body,
);
};

0 comments on commit 16cffe8

Please sign in to comment.