ng-bootstrap icon indicating copy to clipboard operation
ng-bootstrap copied to clipboard

Modal: consider supporting stacked modals

Open pkozlowski-opensource opened this issue 10 years ago • 42 comments

That is - modals that can be opened from modals. The current thinking is:

  • we are very reluctant to support those as it is very, very bad UX
  • "real life" sometimes "requires" those anyway....

Will try to resist us long as possible before implementing stacked modals, but let's have this issue to track interest / real-life usage scenarios.

pkozlowski-opensource avatar Aug 31 '16 09:08 pkozlowski-opensource

I think it should be supported (for your record)

natcohen avatar Aug 31 '16 21:08 natcohen

I use modal for yes/no confirmation dialogs. However, if stacked modals aren't supported this means you can't have 'normal' modals with data entry which then uses modal confirmation dialogs. I guess one could argue data entry in modals are a bad UX?

Quinn-L avatar Aug 31 '16 23:08 Quinn-L

Yeh, I'm kind of resigning to the reality of many projects and bracing for supporting this... But won't get to it before we land datepicker.

pkozlowski-opensource avatar Sep 01 '16 11:09 pkozlowski-opensource

Voice in the discussion: https://github.com/twbs/bootstrap/issues/20607#issuecomment-244127770

pkozlowski-opensource avatar Sep 01 '16 16:09 pkozlowski-opensource

I also agree with @pkozlowski-opensource stacked modal aren't good from UX perspective. Also, we had huge number of problems in one of large SPA build in Angular 1. Where there were confirmation dialogs, terms dialogs on top of existing dialogs, which caused more complexity, especially when in a web app reload happens, it is difficult to maintain state for those. We totally scrappeed the idea of having functional templates in modal. only for confirmation dialogs etc.

asadsahi avatar Sep 08 '16 13:09 asadsahi

Is there any plans to support backdrop position in between stacked modals? It turns that for each inner modal its backdrop doesn't cover previous modal.

There is some quick reproduction: http://plnkr.co/edit/FG03lIbHjzM9wAZMoLWL?p=preview

tytskyi avatar Dec 29 '16 15:12 tytskyi

@pkozlowski-opensource If this is considered by the team to be "very, very bad UX," what is the suggested alternative when several closely associated components need to operate on the same data? Especially with data that's already loaded? @ViewChild and direct subcomponent access? Child routes (and the terrible API of having to have a singleton service to pass references to in-memory data)?

xentopos avatar Jan 05 '17 16:01 xentopos

@pkozlowski-opensource As you already said, sometimes we need stacked modals anyway. What is the alternative approach suggested by you till the library support stacked modals ?

ASHFAQPATWARI avatar Jan 21 '17 10:01 ASHFAQPATWARI

@pkozlowski-opensource is there any progress on this matter?

DocteurEz avatar Feb 08 '17 00:02 DocteurEz

When opening a modal(2) within a modal(1) it doesn't apply a backdrop to modal 1

ravtakhar avatar Feb 12 '17 00:02 ravtakhar

Not sure where you are at on this issue, but I agree multiple modals are needed. In my instance I'm working on an address component what when you click edit opens a modal (because the edit controls take up much more place than a read-only address displayed in the DOM), I don't want to limit the component to only working outside of modals. In fact, I find it frustrating looking over the documentation that you are building an alternative implementation of Bootstrap.js, but treat modals so entirely different. I don't understand why instead of using divs and modal classes, why we need to use templates and host it in a special tag somewhere in the modal. From what I can tell, none of your other controls are imposing a different design than the standard Bootstrap.

I can understand you wanting to do it a particular way for ease of use for what you consider the common design pattern, but I can't see the justification for eliminating my ability to stick my modals anywhere in my HTML DOM that I chose and open them anyway I please.

dguisinger avatar Feb 23 '17 03:02 dguisinger

There is also a problem when the first modal has a scroll bar... when you open a stacked modal over the first one and close it, it becomes impossible to scroll the first one.

Reproduce here: http://plnkr.co/edit/ZGYAbyJXwn8IWqz4sme8?p=preview

  • Open by clicking Launch demo
  • Scroll down and click on the stacked button
  • Close the small modal
  • Try to scroll again, it won't work...

natcohen avatar May 03 '17 13:05 natcohen

Any updates on this? I would like to have the first modal included in the backdrop when the second modal is opened.

Quick fix is to add the following style: Assuming the backdrops/modals are added correctly in the DOM .modal-backdrop { z-index:1050; }

Vx2gas avatar May 26 '17 17:05 Vx2gas

@Vx2gas, z-index helps to some extent (the second modal backdrop is shown now over the first modal), but it doesn't fix the issue with scrolling: http://plnkr.co/edit/3cISZTeEoqfb76KaC12z?p=preview

dmitrysteblyuk avatar Jun 05 '17 08:06 dmitrysteblyuk

@dmitrysteblyuk, your right. Anyone got a fix for this?

Vx2gas avatar Jun 05 '17 14:06 Vx2gas

@Vx2gas the issue was that NgbModalRef removes modal-open class from body on destroy (despite that the first modal is still open). I added for myself this quick fix

modalRef.result.catch(() => {})
    .then(() => {
        if (document.querySelector('body > .modal')) {
            document.body.classList.add('modal-open');
        }
    });

dmitrysteblyuk avatar Jun 05 '17 17:06 dmitrysteblyuk

It seems, adding z-index for modal backdrop and modal-open class for body fixes all the mentioned above issues. I tested only in browser platform though.

dmitrysteblyuk avatar Jun 05 '17 18:06 dmitrysteblyuk

Anyone for a PR?

natcohen avatar Jun 21 '17 15:06 natcohen

An alternative to stacking modals would be the ability to switch between modals.

I attempted to do this manually: have a child component emit an event when it has a modal open. The parent (with it's own modal) could close the parent modal when the child is open, and reopen the parent modal when the child closes. However, calling modalRef.close on the parent appears to detach all modal listeners. The child's modalRef.result.then never fires, so I can't emit an event when the child closes.

Looks like the windowCmptRef gets nullified on close (modal-ref.ts line 98), and windowCmptRef is what is responsible for subscribing to close events (modal-ref.ts line 54). Is it possible that all modals are sharing the same windowCmptRef? It gets assigned at (modal-stack.ts line 52).

Plunkr of the issue here.

ansorensen avatar Aug 21 '17 01:08 ansorensen

Just to add my 2c, when you say:

it is very, very bad UX

Twitter themselves use stacked modals - try going to a tweet and clicking on the picture.

lyonzy avatar Oct 10 '17 03:10 lyonzy