Skip to content

Commit

Permalink
Add selectedItem property
Browse files Browse the repository at this point in the history
  • Loading branch information
blasten committed Aug 20, 2015
1 parent a42ca09 commit d65acd0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
16 changes: 15 additions & 1 deletion src/lib/template/array-selector.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@
notify: true
},

/**
* When `multi` is false, this is the currently selected item, or `null`
* if no item is selected.
*/
selectedItem: {
type: Object,
notify: true
},

/**
* When `true`, calling `select` on an item that is already selected
* will deselect the item.
Expand Down Expand Up @@ -132,6 +141,7 @@
this.selected = null;
this._selectedColl = null;
}
this.selectedItem = null;
},

/**
Expand Down Expand Up @@ -164,7 +174,9 @@
}
} else {
this.selected = null;
this.selectedItem = null;
this.unlinkPaths('selected');
this.unlinkPaths('selectedItem');
}
},

Expand Down Expand Up @@ -192,8 +204,10 @@
if (this.toggle && item == this.selected) {
this.deselect();
} else {
this.linkPaths('selected', 'items.' + key);
this.selected = item;
this.selectedItem = item;
this.linkPaths('selected', 'items.' + key);
this.linkPaths('selectedItem', 'items.' + key);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions test/unit/array-selector.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,39 +37,39 @@
test('single selection', function() {
var el = singleConfigured;
// Nothing selected
assert.strictEqual(el.selected, null);
assert.strictEqual(el.selectedItem, null);
assert.isFalse(el.isSelected(el.items[0]));
assert.isFalse(el.isSelected(el.items[1]));
assert.isFalse(el.isSelected(el.items[2]));
// Select 0
el.select(el.items[0]);
assert.strictEqual(el.selected, el.items[0]);
assert.strictEqual(el.selectedItem, el.items[0]);
assert.isTrue(el.isSelected(el.items[0]));
assert.isFalse(el.isSelected(el.items[1]));
assert.isFalse(el.isSelected(el.items[2]));
// Re-select 0
el.select(el.items[0]);
assert.strictEqual(el.selected, el.items[0]);
assert.strictEqual(el.selectedItem, el.items[0]);
assert.isTrue(el.isSelected(el.items[0]));
assert.isFalse(el.isSelected(el.items[1]));
assert.isFalse(el.isSelected(el.items[2]));
// Select 2
el.select(el.items[2]);
assert.strictEqual(el.selected, el.items[2]);
assert.strictEqual(el.selectedItem, el.items[2]);
assert.isFalse(el.isSelected(el.items[0]));
assert.isFalse(el.isSelected(el.items[1]));
assert.isTrue(el.isSelected(el.items[2]));
// Toggle 2
el.toggle = true;
el.select(el.items[2]);
assert.strictEqual(el.selected, null);
assert.strictEqual(el.selectedItem, null);
assert.isFalse(el.isSelected(el.items[0]));
assert.isFalse(el.isSelected(el.items[1]));
assert.isFalse(el.isSelected(el.items[2]));
// Toggle 2
el.toggle = true;
el.select(el.items[2]);
assert.strictEqual(el.selected, el.items[2]);
assert.strictEqual(el.selectedItem, el.items[2]);
assert.isFalse(el.isSelected(el.items[0]));
assert.isFalse(el.isSelected(el.items[1]));
assert.isTrue(el.isSelected(el.items[2]));
Expand Down

0 comments on commit d65acd0

Please sign in to comment.