To be able to select my mouse click and drag, do the following:
Set the css property user-select: none;
to the element which holds your selectable items.
Add on-track="handleTrack"
to the element which holds your selectable items.
Put this div somewhere in your element: <div id="selectionBox" style="position:absolute; top:0; left:0; height:0; width:0; border:2px solid #000; background-color:rgba(128, 128, 128, 0.3); z-index:999;"></div>
Then, add these functions to your element:
handleTrack: function(e) {
switch(e.detail.state) {
case "start":
this.x1 = e.detail.x;
this.y1 = e.detail.y;
this.drawRectangle(this.x1, this.y1, this.x2, this.y2);
break;
case "track":
this.x2 = e.detail.x;
this.y2 = e.detail.y;
this.drawRectangle(this.x1, this.y1, this.x2, this.y2);
break;
case "end":
this.x2 = e.detail.x;
this.y2 = e.detail.y;
this.drawRectangle(0, 0, 0, 0);
this.selectRectangle(e);
break;
}
},
drawRectangle: function(x1, y1, x2, y2) {
this.$.selectionBox.style.left = x1 + 'px';
this.$.selectionBox.style.top = y1 + 'px';
this.$.selectionBox.style.width = (x2 - x1) + 'px';
this.$.selectionBox.style.height = (y2 - y1) + 'px';
},
selectRectangle: function(e) {
var tol = 20;
var ironSelectors = Polymer.dom(e.currentTarget).querySelectorAll("iron-selector");
ironSelectors.forEach(function(selector) {
selector.items.forEach(function(i) {
var el = i.getBoundingClientRect();
if ((el.left+tol >= this.x1) && (el.top+tol >= this.y1) && (el.right-tol <= this.x2) && (el.bottom-tol <= this.y2)) {
selector.select(i.value);
}
}.bind(this));
}.bind(this));
}
This code also works if you have multiple iron-selector
.