Contact link in header #3
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I need to add to the header nav the contact link that goes to the same link as what is in the footer.
Plan
The footer Contact opens a modal (via
ContactModalcomponent) — it is not a page link. To match that behavior in the header:Changes to
src/components/layout/Header.tsxContactModalfrom../shared/ContactModaluseStateforisContactModalOpen(already importsuseState)<ContactModal>at the bottom of the header componentNo new pages or routes needed. The modal handles the form submission just as it does in the footer.
Please reply with approved to proceed, or let me know if you want a different approach (e.g., a
/contactpage instead of a modal).Approved.
Done
Deployed commit
1c79957— Contact link added to the header nav (desktop and mobile), triggering the same ContactModal used in the footer.Changes made to
src/components/layout/Header.tsx:ContactModalisContactModalOpenstate<ContactModal>at the bottom of the header componentSite verified healthy at http://localhost:803/ after deploy.
Good job but it has a bug. After I click contact at top right corner of the website-- the nav header, it pops up that takes up top half of the screen-- the contact popup needs to be moved down to be in the middle of the webpage. See the attached screenshot.
Bug Analysis
The modal appears at the top of the screen because
<ContactModal>is rendered as a child of<motion.header>. Framer Motion applies CSStransformto animate the header sliding in — and when a parent element has an active CSS transform, anyposition: fixedchildren are positioned relative to that transformed ancestor, not the viewport. So the modal backdrop only covers the header area.Plan
Modify
src/components/shared/ContactModal.tsxto render the modal overlay viaReactDOM.createPortalintodocument.body. This makes the modal escape any stacking context no matter where in the component tree it is placed, so it always covers the full viewport and centers correctly.Change: Wrap the
<AnimatePresence>block in a portal —ReactDOM.createPortal(content, document.body)— guarded by amountedstate (required for Next.js SSR safety).No changes needed to
Header.tsxorFooter.tsx. The Footer modal will also benefit from this fix.Please reply with approved to proceed, or let me know if you prefer a different approach.
Revised Plan — Fix Modal Centering
Root cause: The ContactModal is rendered inside motion.header, which applies a CSS transform (the slide-in animation: y: -100 to y: 0). CSS transforms create a new containing block for fixed-positioned descendants, so the modal ends up anchored to the header instead of the full viewport — explaining why it appears only in the top half of the screen.
Fix: Use a React portal in ContactModal.tsx to render the modal directly at document.body, bypassing the header transform context. No changes to Header.tsx needed.
Change to src/components/shared/ContactModal.tsx
This ensures the modal backdrop and dialog render at the top of the DOM tree, centered in the full viewport regardless of where in the component tree the modal is placed.
Please reply approved to proceed.
Approved. Just make sure the contact link at the bottom is also having the modal centerized in the middle as well.
Done
Deployed commit
10ae434— ContactModal centering fixed for both header and footer.Change:
src/components/shared/ContactModal.tsxnow renders viaReactDOM.createPortalintodocument.body, escaping the CSS transform stacking context created bymotion.header's slide-in animation. The modal backdrop now covers the full viewport and centers the dialog correctly regardless of where in the component tree it is placed — so both the header Contact button and the footer Contact link open the modal centered in the middle of the page.Site verified healthy at http://localhost:803/.