PolymerElements/paper-radio-group

Focusing from javascript when no selected error

Closed this issue · 6 comments

When focusing the element via javascript and no selected property:

Uncaught TypeError: Cannot read property 'disabled' of undefined
Polymer.selectNext @ paper-radio-group.html:180
Polymer.IronA11yKeysBehavior._triggerKeyHandler @ iron-a11y-keys-behavior.html:439
Polymer.IronA11yKeysBehavior._onKeyBindingEvent @ iron-a11y-keys-behavior.html:423

Must check first if selected is defined:

--- webcomponents/polymer-starter-kit-1.2.3/app/bower_components/paper-radio-group/paper-radio-group.html   (revision )
+++ webcomponents/polymer-starter-kit-1.2.3/app/bower_components/paper-radio-group/paper-radio-group.html   (revision )
@@ -158,7 +158,7 @@
      */
     selectPrevious: function() {
       var length = this.items.length;
-      var newIndex = Number(this._valueToIndex(this.selected));
+      var newIndex = this.selected ? Number(this._valueToIndex(this.selected)): 0;

       do {
         newIndex = (newIndex - 1 + length) % length;
@@ -173,7 +173,7 @@
      */
     selectNext: function() {
       var length = this.items.length;
-      var newIndex = Number(this._valueToIndex(this.selected));
+      var newIndex = this.selected ? Number(this._valueToIndex(this.selected)): length - 1;

       do {
         newIndex = (newIndex + 1 + length) % length;

(edited by @bicknellr: wrapped diff block in backticks)

This is fixed as of v1.2.0: http://output.jsbin.com/kukoxeb .
(Example breaking w/ v1.1.0: http://output.jsbin.com/wulawa .)

@bicknellr
if next or previous button trigger selectNext or selectPrevious in paper-radio-group, the problem still persists: javascript works but clicking on next or previous buttons do not select first or last item respectivelly

Confirmed: not working on Windows 7 in any browser: chrome 50.0, firefox 46.0.1 and iexplorer 10

Also not working on Centos 7 with chorme 50.0 and firefox 45.1

Ok, thanks for the feedback. I'll file this is as a separate IronSelectableBehavior bug.

@bicknellr
apply patch provided