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.

Should modal always be appened to document.body?

See original GitHub issue

My app consists of various sidebar / menubar with various z-index / position CSS parameters. When I use b-modal inside my component, it tries to render the dialog inside the div where the child component is located which might be buried under other div / scroll bars, etc.

brain life

It looks like I can fix this simply by moving the b-modal to document.body via mounted() hook on the component that’s hosting the dialog

   mounted() {
        document.body.appendChild(this.$refs.modal.$el);
    },

My app now looks like this.

brain life 1

My question is, shouldn’t the modal always be moved to the body for it to be rendered as designed? (Or at least moved to body by default while allowing user to not move it if they so choose via b-modal option?)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
tmorehousecommented, Apr 22, 2019

@soichih the next release of BootstrapVue (next release after 2.0.0-rc.19) will be using PortalVue to render the modal appended to the <body> element, by default (and modals will always be rendered lazily by default).

0reactions
tmorehousecommented, Oct 17, 2017

The issue with fix-positioned parent containers is documented in Bootstrap V4 (and V3) https://getbootstrap.com/docs/4.0/components/modal/#how-it-works:

Modals use position: fixed, which can sometimes be a bit particular about its rendering. Whenever possible, place your modal HTML in a top-level position to avoid potential interference from other elements. You’ll likely run into issues when nesting a .modal within another fixed element.

Since Bootstrap-Vue is based on Boostrap V4.beta CSS, it inherits the issues associated with Boostrap V4.beta’s CSS.

Basically, place your modal (or <b-modal>) component outside of any fixed position containers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create a React Modal (which is appended to <body ...
The fundamental problem here is that in React you're only allowed to mount component to its parent, which is not always the desired...
Read more >
How to create a modal in Javascript | by Marvin Clerge
Modals can be an incredibly useful tool in building a website. ... Then append the child to the modal, and modal to the...
Read more >
Modal
Modals are built with HTML, CSS, and JavaScript. They're positioned over everything else in the document and remove scroll from the <body> so...
Read more >
react-modal documentation
Using a custom parent node. By default, the modal portal will be appended to the document's body. You can choose a different parent...
Read more >
How to Create a Modal Window For Your Websites - YouTube
... to create a custom modal window for use on your websites using plain HTML, CSS & JavaScript. This is very easy to...
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