Skip to content

Commit 653b02c

Browse files
committed
adapt selectOption for singleSelect
1 parent b017b20 commit 653b02c

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

web/dropdown.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,24 @@ class Dropdown {
146146
*/
147147
public selectOption(value: string) {
148148
const optionIndex = this.options.findIndex((option) => value === option.value);
149-
if (this.multipleAllowed && optionIndex > -1 && !this.optionsSelected[0] && !this.optionsSelected[optionIndex]) {
149+
if (optionIndex < 0 && (this.optionsSelected[0] || this.optionsSelected[optionIndex])) return;
150+
if (this.multipleAllowed) {
150151
// Select the option with the specified value
151152
this.optionsSelected[optionIndex] = true;
152-
153-
// A change has occurred, re-render the dropdown options
154-
const menuScroll = this.menuElem.scrollTop;
155-
this.render();
156-
if (this.dropdownVisible) {
157-
this.menuElem.scroll(0, menuScroll);
153+
} else {
154+
for (let i = 1; i < this.optionsSelected.length; i++) {
155+
this.optionsSelected[i] = false;
158156
}
159-
this.changeCallback(this.getSelectedOptions(false));
157+
this.optionsSelected[optionIndex] = true;
160158
}
159+
// A change has occurred, re-render the dropdown options
160+
const menuScroll = this.menuElem.scrollTop;
161+
this.render();
162+
if (this.dropdownVisible) {
163+
this.menuElem.scroll(0, menuScroll);
164+
}
165+
this.changeCallback(this.getSelectedOptions(false));
166+
161167
}
162168

163169
/**

0 commit comments

Comments
 (0)