Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Unified Diff: third_party/polymer/v1_0/components-chromium/paper-radio-group/paper-radio-group-extracted.js

Issue 1187823002: Update Polymer components and re-run reproduce.sh (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/polymer/v1_0/components-chromium/paper-radio-group/paper-radio-group-extracted.js
diff --git a/third_party/polymer/v1_0/components-chromium/paper-radio-group/paper-radio-group-extracted.js b/third_party/polymer/v1_0/components-chromium/paper-radio-group/paper-radio-group-extracted.js
index 6de17dc0b7ebc43582e45461b1438a287255ab9b..115b8d9851f9d095765f20741b0a9344269261a8 100644
--- a/third_party/polymer/v1_0/components-chromium/paper-radio-group/paper-radio-group-extracted.js
+++ b/third_party/polymer/v1_0/components-chromium/paper-radio-group/paper-radio-group-extracted.js
@@ -3,7 +3,8 @@
is: 'paper-radio-group',
behaviors: [
- Polymer.IronA11yKeysBehavior
+ Polymer.IronA11yKeysBehavior,
+ Polymer.IronSelectableBehavior
],
hostAttributes: {
@@ -13,115 +14,75 @@
properties: {
/**
- * Fired when the selected element changes to user interaction.
- *
- * @event paper-radio-group-changed
+ * Overriden from Polymer.IronSelectableBehavior
*/
+ attrForSelected: {
+ type: String,
+ value: 'name'
+ },
/**
- * Gets or sets the selected element. Use the `name` attribute of the
- * <paper-radio-button> that should be selected.
- *
- * @attribute selected
- * @type String
- * @default null
+ * Overriden from Polymer.IronSelectableBehavior
*/
-
- selected: {
+ selectedAttribute: {
type: String,
- value: null,
- notify: true,
- reflectToAttribute: true,
- observer: "_selectedChanged"
+ value: 'checked'
}
},
keyBindings: {
- 'left up': '_selectPrevious',
- 'right down': '_selectNext',
+ 'left up': 'selectPrevious',
+ 'right down': 'selectNext',
},
- _selectedChanged: function() {
- // TODO: This only needs to be async while a domReady event is unavailable.
- this.async(function() {
- this._selectIndex(this._valueToIndex(this.items, this.selected));
- this.fire('paper-radio-group-changed');
- });
- },
+ /**
+ * Selects the given value.
+ */
+ select: function(value) {
+ if (this.selected) {
+ var oldItem = this._valueToItem(this.selected);
+
+ // Do not allow unchecking the selected item.
+ if (this.selected == value) {
+ oldItem.checked = true;
+ return;
+ }
- _selectNext: function() {
- this.selected = this._nextNode();
- },
+ if (oldItem)
+ oldItem.checked = false;
+ }
- _selectPrevious: function() {
- this.selected = this._previousNode();
+ Polymer.IronSelectableBehavior.select.apply(this, [value]);
+ this.fire('paper-radio-group-changed');
},
/**
- * Returns an array of all items.
- *
- * @property items
- * @type array
+ * Selects the previous item. If the previous item is disabled, then it is
+ * skipped, and its previous item is selected
*/
- get items() {
- return Polymer.dom(this.$.items).getDistributedNodes();
- },
+ selectPrevious: function() {
+ var length = this.items.length;
+ var newIndex = Number(this._valueToIndex(this.selected));
- _nextNode: function() {
- var items = this.items;
- var index = this._selectedIndex;
- var newIndex = index;
do {
- newIndex = (newIndex + 1) % items.length;
- if (newIndex === index) {
- break;
- }
- } while (items[newIndex].disabled);
- return this._valueForNode(items[newIndex]);
- },
+ newIndex = (newIndex - 1 + length) % length;
+ } while (this.items[newIndex].disabled)
- _previousNode: function() {
- var items = this.items;
- var index = this._selectedIndex;
- var newIndex = index;
- do {
- newIndex = (newIndex || items.length) - 1;
- if (newIndex === index) {
- break;
- }
- } while (items[newIndex].disabled);
- return this._valueForNode(items[newIndex]);
+ this.select(this._indexToValue(newIndex));
},
- _selectIndex: function(index) {
- if (index == this._selectedIndex)
- return;
-
- var nodes = this.items;
-
- // If there was a previously selected node, deselect it.
- if (nodes[this._selectedIndex]) {
- nodes[this._selectedIndex].checked = false;
- }
+ /**
+ * Selects the next item. If the next item is disabled, then it is
+ * skipped, and its nexy item is selected
+ */
+ selectNext: function() {
+ var length = this.items.length;
+ var newIndex = Number(this._valueToIndex(this.selected));
- // Select a new node.
- nodes[index].checked = true;
- nodes[index].focus();
- this._selectedIndex = index;
- },
+ do {
+ newIndex = (newIndex + 1 + length) % length;
+ } while (this.items[newIndex].disabled)
- _valueForNode: function(node) {
- return node["name"] || node.getAttribute("name");
+ this.select(this._indexToValue(newIndex));
},
-
- // Finds an item with value == |value| and return its index.
- _valueToIndex: function(items, value) {
- for (var index = 0, node; (node = items[index]); index++) {
- if (this._valueForNode(node) == value) {
- return index;
- }
- }
- // If no item found, the value itself is probably the index.
- return value;
- }
});

Powered by Google App Engine
This is Rietveld 408576698