Fix template types in gr-dropdown-list
Change-Id: If4aa216e3c990066dcdbc6c25d544513e40f1979
diff --git a/polygerrit-ui/app/BUILD b/polygerrit-ui/app/BUILD
index 4cafc7c..1c0ab00 100644
--- a/polygerrit-ui/app/BUILD
+++ b/polygerrit-ui/app/BUILD
@@ -131,7 +131,6 @@
"elements/shared/gr-account-list/gr-account-list_html.ts",
"elements/shared/gr-comment-thread/gr-comment-thread_html.ts",
"elements/shared/gr-comment/gr-comment_html.ts",
- "elements/shared/gr-dropdown-list/gr-dropdown-list_html.ts",
]
sources_for_template_checking = glob(
diff --git a/polygerrit-ui/app/elements/shared/gr-dropdown-list/gr-dropdown-list.ts b/polygerrit-ui/app/elements/shared/gr-dropdown-list/gr-dropdown-list.ts
index ef46cec..6180f35 100644
--- a/polygerrit-ui/app/elements/shared/gr-dropdown-list/gr-dropdown-list.ts
+++ b/polygerrit-ui/app/elements/shared/gr-dropdown-list/gr-dropdown-list.ts
@@ -88,7 +88,7 @@
disabled = false;
@property({type: String, notify: true})
- value?: string;
+ value: string | number = '';
@property({type: Boolean})
showCopyForTriggerText = false;
@@ -122,6 +122,10 @@
return item.mobileText ? item.mobileText : item.text;
}
+ computeStringValue(val: string | number) {
+ return String(val);
+ }
+
@observe('value', 'items')
_handleValueChange(value?: string, items?: DropdownItem[]) {
if (!value || !items) {
diff --git a/polygerrit-ui/app/elements/shared/gr-dropdown-list/gr-dropdown-list_html.ts b/polygerrit-ui/app/elements/shared/gr-dropdown-list/gr-dropdown-list_html.ts
index 2ff1936..3875871 100644
--- a/polygerrit-ui/app/elements/shared/gr-dropdown-list/gr-dropdown-list_html.ts
+++ b/polygerrit-ui/app/elements/shared/gr-dropdown-list/gr-dropdown-list_html.ts
@@ -173,7 +173,10 @@
<gr-select bind-value="{{value}}">
<select>
<template is="dom-repeat" items="[[items]]">
- <option disabled$="[[item.disabled]]" value="[[item.value]]">
+ <option
+ disabled$="[[item.disabled]]"
+ value="[[computeStringValue(item.value)]]"
+ >
[[_computeMobileText(item)]]
</option>
</template>
diff --git a/polygerrit-ui/app/elements/shared/gr-select/gr-select.ts b/polygerrit-ui/app/elements/shared/gr-select/gr-select.ts
index e71add9..571272d 100644
--- a/polygerrit-ui/app/elements/shared/gr-select/gr-select.ts
+++ b/polygerrit-ui/app/elements/shared/gr-select/gr-select.ts
@@ -34,7 +34,7 @@
}
@property({type: String, notify: true})
- bindValue?: string;
+ bindValue?: string | number;
get nativeSelect() {
// gr-select is not a shadow component
@@ -49,14 +49,12 @@
// 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;
+ this.nativeSelect.value = String(this.bindValue);
// Async needed for firefox to populate value. It was trying to do it
// before options from a dom-repeat were rendered previously.
// See https://bugs.chromium.org/p/gerrit/issues/detail?id=7735
setTimeout(() => {
- // TODO(TS): maybe should check for undefined before assigning
- // or fallback to ''
- this.nativeSelect.value = this.bindValue!;
+ this.nativeSelect.value = String(this.bindValue);
}, 1);
}
}