| OLD | NEW |
| 1 Polymer({ | 1 Polymer({ |
| 2 is: 'paper-radio-group', | 2 is: 'paper-radio-group', |
| 3 | 3 |
| 4 behaviors: [ | 4 behaviors: [ |
| 5 Polymer.IronA11yKeysBehavior, | 5 Polymer.IronMenubarBehavior |
| 6 Polymer.IronSelectableBehavior | |
| 7 ], | 6 ], |
| 8 | 7 |
| 9 hostAttributes: { | 8 hostAttributes: { |
| 10 role: 'radiogroup', | 9 role: 'radiogroup', |
| 11 tabindex: 0 | 10 tabindex: 0 |
| 12 }, | 11 }, |
| 13 | 12 |
| 14 properties: { | 13 properties: { |
| 15 /** | 14 /** |
| 16 * Fired when the radio group selection changes. | 15 * Fired when the radio group selection changes. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 44 | 43 |
| 45 /** | 44 /** |
| 46 * If true, radio-buttons can be deselected | 45 * If true, radio-buttons can be deselected |
| 47 */ | 46 */ |
| 48 allowEmptySelection: { | 47 allowEmptySelection: { |
| 49 type: Boolean, | 48 type: Boolean, |
| 50 value: false | 49 value: false |
| 51 } | 50 } |
| 52 }, | 51 }, |
| 53 | 52 |
| 54 keyBindings: { | |
| 55 'left up': 'selectPrevious', | |
| 56 'right down': 'selectNext', | |
| 57 }, | |
| 58 | |
| 59 /** | 53 /** |
| 60 * Selects the given value. | 54 * Selects the given value. |
| 61 */ | 55 */ |
| 62 select: function(value) { | 56 select: function(value) { |
| 57 var newItem = this._valueToItem(value); |
| 58 if (newItem && newItem.hasAttribute('disabled')) { |
| 59 return; |
| 60 } |
| 61 |
| 63 if (this.selected) { | 62 if (this.selected) { |
| 64 var oldItem = this._valueToItem(this.selected); | 63 var oldItem = this._valueToItem(this.selected); |
| 65 | 64 |
| 66 if (this.selected == value) { | 65 if (this.selected == value) { |
| 67 // If deselecting is allowed we'll have to apply an empty selection. | 66 // If deselecting is allowed we'll have to apply an empty selection. |
| 68 // Otherwise, we should force the selection to stay and make this | 67 // Otherwise, we should force the selection to stay and make this |
| 69 // action a no-op. | 68 // action a no-op. |
| 70 if (this.allowEmptySelection) { | 69 if (this.allowEmptySelection) { |
| 71 value = ''; | 70 value = ''; |
| 72 } else { | 71 } else { |
| 73 if (oldItem) | 72 if (oldItem) |
| 74 oldItem.checked = true; | 73 oldItem.checked = true; |
| 75 return; | 74 return; |
| 76 } | 75 } |
| 77 } | 76 } |
| 78 | 77 |
| 79 if (oldItem) | 78 if (oldItem) |
| 80 oldItem.checked = false; | 79 oldItem.checked = false; |
| 81 } | 80 } |
| 82 | 81 |
| 83 Polymer.IronSelectableBehavior.select.apply(this, [value]); | 82 Polymer.IronSelectableBehavior.select.apply(this, [value]); |
| 84 this.fire('paper-radio-group-changed'); | 83 this.fire('paper-radio-group-changed'); |
| 85 }, | 84 }, |
| 86 | 85 |
| 87 /** | 86 _activateFocusedItem: function() { |
| 88 * Selects the previous item. If the previous item is disabled, then it is | 87 this._itemActivate(this._valueForItem(this.focusedItem), this.focusedItem)
; |
| 89 * skipped, and its previous item is selected | |
| 90 */ | |
| 91 selectPrevious: function() { | |
| 92 var length = this.items.length; | |
| 93 var newIndex = Number(this._valueToIndex(this.selected)); | |
| 94 | |
| 95 do { | |
| 96 newIndex = (newIndex - 1 + length) % length; | |
| 97 } while (this.items[newIndex].disabled) | |
| 98 | |
| 99 this._itemActivate(this._indexToValue(newIndex), this.items[newIndex]); | |
| 100 }, | 88 }, |
| 101 | 89 |
| 102 /** | 90 _onUpKey: function(event) { |
| 103 * Selects the next item. If the next item is disabled, then it is | 91 this._focusPrevious(); |
| 104 * skipped, and the next item after it is selected. | 92 event.preventDefault(); |
| 105 */ | 93 this._activateFocusedItem(); |
| 106 selectNext: function() { | 94 }, |
| 107 var length = this.items.length; | |
| 108 var newIndex = Number(this._valueToIndex(this.selected)); | |
| 109 | 95 |
| 110 do { | 96 _onDownKey: function(event) { |
| 111 newIndex = (newIndex + 1 + length) % length; | 97 this._focusNext(); |
| 112 } while (this.items[newIndex].disabled) | 98 event.preventDefault(); |
| 99 this._activateFocusedItem(); |
| 100 }, |
| 113 | 101 |
| 114 this._itemActivate(this._indexToValue(newIndex), this.items[newIndex]); | 102 _onLeftKey: function(event) { |
| 103 Polymer.IronMenubarBehaviorImpl._onLeftKey.apply(this, arguments); |
| 104 this._activateFocusedItem(); |
| 115 }, | 105 }, |
| 106 |
| 107 _onRightKey: function(event) { |
| 108 Polymer.IronMenubarBehaviorImpl._onRightKey.apply(this, arguments); |
| 109 this._activateFocusedItem(); |
| 110 } |
| 116 }); | 111 }); |
| OLD | NEW |