diff --git a/src/lib/template/array-selector.html b/src/lib/template/array-selector.html index 97d0202d2a..613b898f9f 100644 --- a/src/lib/template/array-selector.html +++ b/src/lib/template/array-selector.html @@ -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. @@ -132,6 +141,7 @@ this.selected = null; this._selectedColl = null; } + this.selectedItem = null; }, /** @@ -164,7 +174,9 @@ } } else { this.selected = null; + this.selectedItem = null; this.unlinkPaths('selected'); + this.unlinkPaths('selectedItem'); } }, @@ -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); } } } diff --git a/test/unit/array-selector.html b/test/unit/array-selector.html index 9b20250f00..670f421084 100644 --- a/test/unit/array-selector.html +++ b/test/unit/array-selector.html @@ -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]));