Fix error when clicking on empty dropdown (#11637)

This commit is contained in:
Charles Gagnon
2020-08-04 14:33:25 -07:00
committed by GitHub
parent e7ec278ef2
commit 0c3798ae26

View File

@@ -704,8 +704,8 @@ export class SelectBoxList extends Disposable implements ISelectBoxDelegate, ILi
let elementWidth = 0; let elementWidth = 0;
if (container) { if (container) {
let longest = 0; let longest = -1;
let longestLength = 0; let longestLength = -1;
this.options.forEach((option, index) => { this.options.forEach((option, index) => {
const len = option.text.length + (!!option.decoratorRight ? option.decoratorRight.length : 0); const len = option.text.length + (!!option.decoratorRight ? option.decoratorRight.length : 0);
@@ -715,8 +715,10 @@ export class SelectBoxList extends Disposable implements ISelectBoxDelegate, ILi
} }
}); });
if (longest >= 0) {
container.innerHTML = this.options[longest].text + (!!this.options[longest].decoratorRight ? (this.options[longest].decoratorRight + ' ') : '');
}
container.innerHTML = this.options[longest].text + (!!this.options[longest].decoratorRight ? (this.options[longest].decoratorRight + ' ') : '');
elementWidth = dom.getTotalWidth(container); elementWidth = dom.getTotalWidth(container);
} }