Showing a gray backdrop with a mixin

纵饮孤独 提交于 2019-12-11 17:58:07

问题


I have a small window that I'm inserting into my page (and removing when the page is closed). I want a grayed-out background behind this window, as on dialogs. So I thought I'd use paper-dialog-behavior or iron-overlay-behavior as a mixin, and set this.withBackdrop = true in my ready() method. However, when I add ...extends Polymer.mixinBehaviors([Polymer.IronOverlayBehavior], Polymer.Element) or ...extends Polymer.mixinBehaviors([Polymer.PaperDialogBehaviorImpl], Polymer.Element) to this element, it never appears.

I tired .open() like on a dialog and was told that it's undefined. I can trace my element loading in DevTools, and no errors print in the console, but it never appears on the screen.

You can see what I'm going for at this pen: https://codepen.io/johnthad/pen/zRLMpe If I swap the class declarations of MyChild for the one with the mixin, the child loads but never displays.


回答1:


You need to call open of MyChild after append:

_doTap(e) {
   . . .
   this.$.placeholder.appendChild(this.mychild);
   this.mychild.open()
}

Then add withBackdrop property to true in MyChild component:

static get properties() {
     return {
         withBackdrop: {
          type: Boolean,
          value: true
        }
     }
}

Here you'll find working code.



来源:https://stackoverflow.com/questions/48938226/showing-a-gray-backdrop-with-a-mixin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!