Polymer element's on-keypress won't fire -


i bind on-keypress event on element declarative event mapping, keypresshandler wont fire. did try answer another question, still same. here dome, element gdg-slider.html, , codes on github.

  <link rel="import" href="bower_components/polymer/polymer.html">   <link rel="import" href="bower_components/core-icons/core-icons.html">   <link href="bower_components/core-animated-pages/core-animated-pages.html" rel="import">   <link href="bower_components/core-animated-pages/transitions/cross-fade.html" rel="import">   <link href="bower_components/core-animated-pages/transitions/slide-from-right.html" rel="import">   <link rel="import" href="bower_components/paper-shadow/paper-shadow.html">    <link rel="import" href="bower_components/paper-fab/paper-fab.html">  <polymer-element name="gdg-slider" on-keypress="{{keypresshandler}}">   <template>   <style>     core-animated-pages{       position: absolute;       top: 0px;       right: 0;       bottom: 0;       left: 0;       font-size: 32px;       overflow: hidden;       background-color: #222;       color: #eee;     }     p,h1,h2,h3,h4,h5{         padding: 5px;         margin: 0;           word-break: break-all;     }     h1{         padding: 10px;     }     section{         width: 100%;     }     section > div {       height: 100%;       padding: 0 30px;     }     section.nav{         position: absolute;         bottom: 30px;         left: 0;     }     section.nav>div{         padding: 0 30px;     }     section.nav>div:first-child{         padding-right: 0;     }     #prebtn{         background: #999;     }     .me{         border-radius: 500px;     }     code{         color: #9f499b;         padding: 0 5px;     }     div{         padding: 5px;     }     a,a:active,a:visited,a:link{         padding: 0 5px;         color: #e7ad52 !important;         text-decoration: none;     }     a:hover{         text-decoration: underline;     }     .right{         position: absolute;         top: -90px;         left: -90px;         width: 170px;         height: 170px;         -webkit-transform: rotate(-45deg);         font-size: 14px;         background: #999;         font-weight: bold;         color: #fff;     }   </style>     <core-animated-pages id="pages" transitions="slide-from-right" selected="{{pageindex}}">      <section style="overflow: hidden;">       <p class="right" layout vertical center end-justified><span>powered polymer</span><paper-shadow z="5"></paper-shadow></p>       <div layout vertical center center-justified>         <img src="resources/images/p-logo.svg"/>         <h1>polymer</h1>         <p>welcome world of tomorrow!</p>       </div>     </section>     <section>       <div layout vertical center-justified>        </div>     </section>     //more sections...   </core-animated-pages>   <section class="nav" layout horizontal end-justified>     <div layout horizontal><paper-fab start-justified icon="icons:arrow-back" id="prebtn" on-click="{{prepage}}"><paper-shadow z="5"></paper-shadow></paper-fab></div>     <div layout horizontal><paper-fab icon="icons:arrow-forward" id="nextbtn" on-click="{{nextpage}}"><paper-shadow z="5"></paper-shadow></paper-fab></div>   </section>   </template>   <script>     polymer('gdg-slider',{         pageindex: 0,         pagemax: 0,         ready: function(){             this.pagemax = this.$.pages.children.length-1;             this.$.pages.focus();             this.pageindex = parseint(window.location.hash.replace('#','') || 0);             this.togglebtns();         },         keypresshandler: function(event, detail, sender){             var code = event.keycode;             if(code==32 || code==39){                 this.nextpage();             }else if(code==37){                 this.prepage();             }         },         prepage: function(){             this.pageindex -= 1;             if(this.pageindex <= 0) {                 this.pageindex = 0;             }             window.location.hash = this.pageindex;             this.togglebtns();         },         nextpage: function() {             this.pageindex += 1;             if(this.pageindex >= this.pagemax) {                 this.pageindex = this.pagemax;             }             window.location.hash = this.pageindex;             this.togglebtns();         },         togglebtns: function(){             if(this.pageindex >= this.pagemax) {                 this.$.nextbtn.hidden = true;             }else{                 this.$.nextbtn.removeattribute('hidden');             }             if(this.pageindex <= 0) {                 this.$.prebtn.hidden = true;             }else{                 this.$.prebtn.removeattribute('hidden');             }         }     });   </script>   </polymer-element> 

you're calling this.$.pages.focus(), haven't given #pages tabindex, it's not focusable. that's why keypress events aren't firing.

add tabindex="0" #pages fix it.

here's working jsbin.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

python - Django-cities exits with "killed" -

python - How to get a widget position inside it's layout in Kivy? -