Skip to content
This repository was archived by the owner on Dec 28, 2024. It is now read-only.

Commit

Permalink
Keep current selection when attrForSelected is reset (#163)
Browse files Browse the repository at this point in the history
* add test

* return null when attrForSelected is null

* keep current selection when resetting attrForSelected

* update selected when attrForSelected becomes null

* TODO revert this once polymer-cli#927 is fixed
  • Loading branch information
valdrinkoshi authored Nov 16, 2017
1 parent 1928a9e commit d5d9a82
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
sudo: required
before_script:
- npm install -g polymer-cli
- npm install -g polymer-cli web-component-tester
- polymer install --variants
env:
global:
Expand All @@ -18,8 +18,8 @@ addons:
packages:
- google-chrome-stable
script:
- xvfb-run polymer test
- xvfb-run wct
- >-
if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then polymer test -s 'default';
if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then wct -s 'default';
fi
dist: trusty
7 changes: 5 additions & 2 deletions iron-selectable.html
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
* @returns Returns the index of the item
*/
indexOf: function(item) {
return this.items.indexOf(item);
return this.items ? this.items.indexOf(item) : -1;
},

/**
Expand Down Expand Up @@ -346,7 +346,10 @@
if (!item) {
return null;
}

if (!this.attrForSelected) {
var i = this.indexOf(item);
return i === -1 ? null : i;
}
var propValue = item[Polymer.CaseMap.dashToCamelCase(this.attrForSelected)];
return propValue != undefined ? propValue : item.getAttribute(this.attrForSelected);
},
Expand Down
9 changes: 9 additions & 0 deletions test/attr-for-selected.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@
done();
});
});

test('setting attr-for-selected to null keeps current selection', function() {
selector.select('value0');
assert.equal(selector.selectedItem, items[0]);
assert.equal(selector.selected, 'value0');
selector.attrForSelected = null;
assert.equal(selector.selectedItem, items[0]);
assert.equal(selector.selected, 0);
});
});

suite('reflected properties as attributes', function() {
Expand Down

0 comments on commit d5d9a82

Please sign in to comment.