Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/modal/modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const StyledModal = styled.div`
/* Container */

const ModalContainer = styled.div`
position: absolute;
position: fixed;
top: 0;
left: 0;
right: 0;
Expand Down
21 changes: 18 additions & 3 deletions src/hooks/use-dropdown.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useContext, useRef, useState } from "react";
import { useContext, useEffect, useRef, useState } from "react";
import DropdownContext from "../components/text-field/dropdown-input/dropdown-context";

function makeRect({ x, y, width } = { x: 0, y: 0, width: 0 }) {
Expand Down Expand Up @@ -36,12 +36,27 @@ function useDropdown({ id, type }) {
setDropdownState((prev) => ({ ...prev, [key]: shows }));
};

const updateDropdownLayout = (target) => {
const rect = calculateDropdownRect(target);
setDropdownRect(rect);
};

const handleTargetClick = (shows) => {
const rect = calculateDropdownRect(targetRef.current);
updateDropdownLayout(targetRef.current);
setShowsDropdown(shows);
setDropdownRect(rect);
};

useEffect(() => {
if (!showsDropdown) return;

function handleWindowResize() {
updateDropdownLayout(targetRef.current);
}

window.addEventListener("resize", handleWindowResize);
return () => window.removeEventListener("resize", handleWindowResize);
}, [showsDropdown, targetRef]);

return {
targetRef,
dropdownRect,
Expand Down
6 changes: 3 additions & 3 deletions src/pages/test-page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ function TestPage() {

const handleToastClick = () => setShowsToast(true);
const handleToastDismiss = () => setShowsToast(false);

/* Modal */
const { showsModal, setShowsModal } = useModal();
const handleModalClick = () => setShowsModal(true);

return (
<div
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
gap: "16px",
margin: 16,
}}
>
<h1>🤯</h1>
Expand Down