mirror of
https://github.com/Polymer/polymer.git
synced 2025-02-25 18:55:30 -06:00
Add selectedItem property
This commit is contained in:
@@ -98,6 +98,15 @@ is false, `selected` is a property representing the last selected item. When
|
||||
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 @@ is false, `selected` is a property representing the last selected item. When
|
||||
this.selected = null;
|
||||
this._selectedColl = null;
|
||||
}
|
||||
this.selectedItem = null;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -164,7 +174,9 @@ is false, `selected` is a property representing the last selected item. When
|
||||
}
|
||||
} else {
|
||||
this.selected = null;
|
||||
this.selectedItem = null;
|
||||
this.unlinkPaths('selected');
|
||||
this.unlinkPaths('selectedItem');
|
||||
}
|
||||
},
|
||||
|
||||
@@ -192,8 +204,10 @@ is false, `selected` is a property representing the last selected item. When
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,39 +37,39 @@ suite('basic', function() {
|
||||
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]));
|
||||
|
||||
Reference in New Issue
Block a user