Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
add selectPrevious()/Next() for selecting previous/next item
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiefu committed Aug 27, 2014
1 parent 39974b4 commit b795f41
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions core-selector.html
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,11 @@
}
},

/**
* Returns an array of all items.
*
* @property items
*/
get items() {
if (!this.target) {
return [];
Expand Down Expand Up @@ -277,6 +282,11 @@
Polymer.removeEventListener(node, this.activateEvent, this.activateListener);
},

/**
* Returns the selected item(s). If the `multi` property is true,
* this will return an array, otherwise it will return
* the selected item or undefined if there is no selection.
*/
get selection() {
return this.$.selection.getSelection();
},
Expand Down Expand Up @@ -418,7 +428,33 @@
}
target = target.parentNode;
}
},

selectIndex: function(index) {
var item = this.items[index];
if (item) {
this.selected = this.valueForNode(item) || index;
}
},

/**
* Selects the previous item. This should be used in single selection only.
*
* @method selectPrevious
*/
selectPrevious: function() {
this.selectIndex(this.selectedIndex - 1);
},

/**
* Selects the next item. This should be used in single selection only.
*
* @method selectNext
*/
selectNext: function() {
this.selectIndex(this.selectedIndex + 1);
}

});
</script>
</polymer-element>

0 comments on commit b795f41

Please sign in to comment.