Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modal dialog doesn't works with app-drawer-layout #295

Closed
2 of 8 tasks
juanmendez92 opened this issue Aug 5, 2016 · 10 comments
Closed
2 of 8 tasks

Modal dialog doesn't works with app-drawer-layout #295

juanmendez92 opened this issue Aug 5, 2016 · 10 comments
Labels

Comments

@juanmendez92
Copy link

Description

When I use the modal version of the paper-dialog, the dialog is covered and I need to delete from the DOM an iron-overlay-backdrop or delete the modal attribute

Expected outcome

Actual outcome

Live Demo

https://jsbin.com/likiwik/edit?html,output

Steps to reproduce

Browsers Affected

  • Chrome
  • Firefox
  • Safari 9
  • Safari 8
  • Safari 7
  • Edge
  • IE 11
  • IE 10
@keanulee
Copy link
Contributor

keanulee commented Aug 5, 2016

@juanmendez92 This is a classic stacking context issue (e.g. PolymerElements/paper-dialog#109). For this reason, we recommend structuring your app such that the dialog is not inside another stacking context (e.g. as a direct child of <body>.

@robdodson
Copy link

To clarify @keanulee's answer a bit. As I understand it, your dialog should be a direct child of <body>. This is because the paper-dialog overlay gets added to body.

Your dialog should not be inside of another custom element like my-view that's nested inside of your app-drawer layout. If you do that then the overlay will end up covering your element.

@ergo
Copy link

ergo commented Aug 21, 2017

@robdodson In a real-life scenario I have something like this:

    <app-drawer-layout>
        <app-header condenses reveals effects="waterfall">
            <app-toolbar>....</app-toolbar>
        </app-header>
        <app-drawer slot="drawer">....</app-drawer>
        <uirouter-uiview>...this injects view elements that will use dialogs...</uirouter-uiview>
    </app-drawer-layout>

I'd expect production applications would use routers injecting view elements inside app-drawer-layout there (which happens to set z-index:0 - thus breaking the functionality). I'm not sure if there is a non-hacky way to use dialogs with app-drawer-layout?

@robdodson
Copy link

@valdrinkoshi

@valdrinkoshi
Copy link
Member

valdrinkoshi commented Aug 23, 2017

The only escape from the stacking-context trap is to declare the element at the Top Layer (aka document's top stacking context).
Proposals like the Blocking Elements stack are in the process of being drafted, but while waiting for it to be available, all you can do is workaround the issue.
<iron-overlay> is based on the idea of using <template> to host overlay content, which <iron-overlay> will stamp at the right spot for you.
I've written a codelab around this topic https://codelabs.developers.google.com/codelabs/building-custom-overlays, in particular check step 5, 6 which explain stacking context issues and how to workaround these. It comes with caveats, especially on content's styling encapsulation & event bubbling.

@ergo
Copy link

ergo commented Aug 23, 2017

@valdrinkoshi I understand, but and maybe I'm missing something, but app-drawer-layout sets its own z-index by default, so there is no way to have modals with default PSK?

You mention step 5 and 6 - but I'm using paper-dialog which is supposed to mitigate the problem as it uses iron-overlay internally.

The problem basicly means one sees the overlay backdrop - but modal is "behind" the overlay.

@valdrinkoshi
Copy link
Member

valdrinkoshi commented Aug 23, 2017

paper-dialog uses iron-overlay-behavior, which doesn't do any reparenting - that would be a breaking change.
iron-overlay is an experiment on exploring the technique of hosting content in a template and stamping it in the right spot.

<paper-dialog>
  <h2>Hello</h2>
</paper-dialog>

<iron-overlay>
  <template>
    <h2>Hello</h2>
  </template>
</iron-overlay>

@ergo
Copy link

ergo commented Aug 23, 2017

Wouldn't that essentially break event emitting? If have foo-view and my dialog emits event for the view - it will not work anymore I believe. I'm starting to think that modals outside the smallest "hello world" demos are impossible to do right now.

@ergo
Copy link

ergo commented Aug 23, 2017

@valdrinkoshi Are you aware of any online examples on how to structure your application to have app-layout and support multiple dialogs depending on different views?

@wesalvaro
Copy link

wesalvaro commented Nov 1, 2017

@ergo I just got hit with this, too. Since the dialogs I care about are larger and more involved, they have their own element. What I do is fire an event from the nested element when I want the dialog opened. The top-level element listens for the event and constructs the dialog.

This is it's handler:

_onDialogOpen(e) {
  const dialog = document.createElement(
      e.detail.dialog);
  const props = e.detail.properties;
  for (let key in props) {
    dialog.set(key, props[key]);
  }
  const root = Polymer.dom(this.root);
  dialog.addEventListener(
      'iron-overlay-closed',
      () => root.removeChild(dialog));
  root.appendChild(dialog);
  dialog.open();
},

It works alright for my use-case right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants