Search code examples
polymerpaper-elements

Polymer paper-drawer-panel not accepting toggle from child


I have a paper-drawer-panel in one element and a toolbar in a child element. On the toolbar is a menu-button, that should toggle the drawer-panel but it does not. How can I tell the paper-drawer-panel to accept a command from the child element?

Parent-element:

<dom-module id="nav-drawer">
<template>
   <paper-drawer-panel drawerFocusSelector="">
      <div drawer id="drawerbox">
         Contents of drawer panel here.
      </div>
      <div main>
         <tool-bar></tool-bar>
      </div>
   <paper-drawer-panel>
</template>
</dom-module>

Child element:

<dom-module id="tool-bar">
  <template>
    <paper-toolbar>
      <paper-icon-button icon="menu" paper-drawer-toggle></paper-icon-button>
    </paper-toolbar>
  </template>
</dom-module>

Thanks for your help. I'm new to Polymer.


Solution

  • I found the answer myself: The tool-bar element I changed as follows, adding attributes and an on-tap function.

    <dom-module id="tool-bar" attributes="togdraw">
      <template>
        <paper-toolbar>
          <paper-icon-button icon="menu" on-tap="toggleDrawer"></paper-icon-button>
        </paper-toolbar>
      </template>
    <script>
    .....
          toggleDrawer: function() {
            this.fire('eventFromChild',{togdraw:"drawer"});
          }
    ....
    </script>
    
    </dom-module>
    

    And the nav-drawer I changed like accordingly:

    <dom-module id="nav-drawer">
    <template>
       <paper-drawer-panel drawerFocusSelector="" selected="{{selectPanel}}">
          <div drawer id="drawerbox">
             Contents of drawer panel here.
          </div>
          <div main>
             <tool-bar></tool-bar>
          </div>
       <paper-drawer-panel>
    </template>
    <script>
    ....
      properties: {
          selectPanel: String
      },
      ready: function() {
        this.addEventListener('eventFromChild', this.toggleDrawer);
      },
      toggleDrawer: function(event,selectPanel) {
        this.selectPanel = event.detail.togdraw;
        return selectPanel;
      }
    ....
    </script>
    </dom-module>