FIX: ensures select-kit can select a row with 0 as value (#8955)

This commit is contained in:
Joffrey JAFFEUX 2020-02-13 09:04:32 +01:00 committed by GitHub
parent e1e74abd4f
commit 42bda52486
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 5 deletions

View File

@ -41,7 +41,7 @@ export default SelectKitComponent.extend({
}, },
select(value, item) { select(value, item) {
if (!value || !value.length) { if (!Ember.isPresent(value)) {
if (!this.validateSelect(this.selectKit.highlighted)) { if (!this.validateSelect(this.selectKit.highlighted)) {
return; return;
} }

View File

@ -421,8 +421,8 @@ export default Component.extend(
} }
if (this.singleSelect) { if (this.singleSelect) {
value = value.firstObject || null; value = Ember.isPresent(value.firstObject) ? value.firstObject : null;
items = items.firstObject || null; items = Ember.isPresent(items.firstObject) ? items.firstObject : null;
} }
this._boundaryActionHandler("onChange", value, items); this._boundaryActionHandler("onChange", value, items);
@ -703,7 +703,7 @@ export default Component.extend(
}, },
select(value, item) { select(value, item) {
if (!value) { if (!Ember.isPresent(value)) {
if (!this.validateSelect(this.selectKit.highlighted)) { if (!this.validateSelect(this.selectKit.highlighted)) {
return; return;
} }

View File

@ -215,3 +215,26 @@ componentTest("content is a basic array", {
assert.equal(this.value, null); assert.equal(this.value, null);
} }
}); });
componentTest("selected value can be 0", {
template: template(),
beforeEach() {
setDefaultState(this, {
value: 1,
content: [
{ id: 0, name: "foo" },
{ id: 1, name: "bar" }
]
});
},
async test(assert) {
assert.equal(this.subject.header().value(), 1);
await this.subject.expand();
await this.subject.selectRowByValue(0);
assert.equal(this.subject.header().value(), 0);
}
});

View File

@ -169,7 +169,7 @@ export default function selectKit(selector) {
}, },
async selectRowByName(name) { async selectRowByName(name) {
await selectKitSelectRowByValue(name, selector); await selectKitSelectRowByName(name, selector);
}, },
async selectNoneRow() { async selectNoneRow() {