From aae6d670a56c234653635062f3de98259e392630 Mon Sep 17 00:00:00 2001 From: Becky Siegel Date: Tue, 5 Dec 2017 17:07:26 -0800 Subject: [PATCH] Fix issue with gr-select when value is 0 There was an issue with gr-select that when the bound value is 0, the native value was not set properly because of the way the value was checked. This change fixes the issue by explicitly checking for undefined rather than falsy value. Change-Id: I1ef33cdb99933e5d2a8ba1fd9360266e8d258eaf --- polygerrit-ui/app/elements/shared/gr-select/gr-select.js | 3 ++- .../app/elements/shared/gr-select/gr-select_test.html | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/polygerrit-ui/app/elements/shared/gr-select/gr-select.js b/polygerrit-ui/app/elements/shared/gr-select/gr-select.js index 21e5e1fd3e..5e0cf30e03 100644 --- a/polygerrit-ui/app/elements/shared/gr-select/gr-select.js +++ b/polygerrit-ui/app/elements/shared/gr-select/gr-select.js @@ -34,7 +34,8 @@ }, _updateValue() { - if (this.bindValue) { + // It's possible to have a value of 0. + if (this.bindValue !== undefined) { // Set for chrome/safari so it happens instantly this.nativeSelect.value = this.bindValue; // Async needed for firefox to populate value. It was trying to do it diff --git a/polygerrit-ui/app/elements/shared/gr-select/gr-select_test.html b/polygerrit-ui/app/elements/shared/gr-select/gr-select_test.html index e7a496503b..2bca29e638 100644 --- a/polygerrit-ui/app/elements/shared/gr-select/gr-select_test.html +++ b/polygerrit-ui/app/elements/shared/gr-select/gr-select_test.html @@ -45,6 +45,11 @@ limitations under the License. element = fixture('basic'); }); + test('value of 0 should still trigger value updates', () => { + element.bindValue = 0; + assert.equal(element.nativeSelect.value, 0); + }); + test('bidirectional binding property-to-attribute', () => { const changeStub = sinon.stub(); element.addEventListener('bind-value-changed', changeStub);