Search code examples
polymerpolymer-2.x

polymer 2 paper-dialog auto open with iron-page inside


I'm totally lost, there's any way to once a page is loaded shows a paper-dialog with an iron-page inside?

I just made it work by binding the dialog to a button, but not as a page_ready event


Solution

  • In the documentation of the paper-dialog you can find a open() method.
    However, I was also able to open it with toggle(). Both seem to work fine.

    this.$.dialogID.toggle();
    this.$.dialogID.open();
    

    In your scenario you want to open the dialog whenever the page is loaded.
    So you could just add this function inside the ready().

    ready() {
      super.ready();
      this.$.dialogID.toggle();
    }
    

    But it might be worth to mention that:

    Polymer no longer guarantees that the initial light DOM distribution is complete before ready is called. (Polymer documentation Lifecycle changes)


    THE CORRECT WAY
    So, I believe you could also just call it on attached. Of course this depends on your elements but it seems to be the easiest and straight forward answer I could come up with.

        constructor() {
            super();
        }
        connectedCallback() {
            super.connectedCallback();
            this.$.dialogID.open();
        }