question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How can I position my modal relative to a parent element in my component?

See original GitHub issue

Summary:

Steps to reproduce:

  1. Set app element to the app root: ReactModal.setAppElement('#root');
  2. Create a basic modal with props like these:
            </nav>
           <ReactModal
               isOpen={state.delete}
               onRequestClose={ () => { setState(prevState => ({ delete: !prevState.delete })) } }
               shouldCloseOnOverlayClick={true}
               className="h-auto m-auto card px-5 py-4"
               style={{
                   overlay: {
                       'background': 'rgba(138, 145, 153, .66)'
                   },
                   content: {
                       'width': '400px',
                       'marginTop': '25vh',
                   }
               }}
           >
  1. Modal is positioned like a fixed element in the center of the viewport.

What I want

I want to position this modal relative to it’s parent component. This modal is for a user menu popup, and it needs to appear below a fixed navbar. The position of the user image is not static. The site is responsive, so the dropdown must be relative to that parent.

Link to example of issue:

https://www.google.com has a similar modal popup when you sign in with an account.

Here is an example image: https://imgur.com/KIykuAc

Any help would be apprecieted.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:14

github_iconTop GitHub Comments

1reaction
cyruscuencacommented, Feb 10, 2022

I have it set to my root. I’ll experiment with attaching it to the navigation bar by ID

1reaction
exaucaecommented, Feb 9, 2022

Have you tried using parentSelector property from the docs?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to position a modal relative to a layout when it's rendered ...
Just put position: absolute to the modal and for the parent, put a position: relative (for all parent like <Left> , <Right> etc)....
Read more >
How to Set Absolute Positioning Relative to the Parent Element
Solution with the CSS position property. It is possible to set absolute positioning of a child element relative to the parent container.
Read more >
Creating a modal inside a relative parent
When i write a modal code inside an element with position relative the modal backdrop is appended to the body and the modal...
Read more >
How to Position a Div Element Over and Relative to Another
Nonetheless, we can set the height and width from CSS. ... The parent is set to relative position and the dialog has absolute...
Read more >
Position an element relatively to another element from ... - WICG
``1. Make the dialog a sibling/ancestor: As long as the dialog and target element are related, I can position: relative; a common parent...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found