From 499d696b681574c00ea32b6e85b548691b6c408b Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Wed, 20 Jul 2022 19:35:08 +0200 Subject: [PATCH] Dropdown now automatically selects the first value, fix #960 --- UI/Input/DropDown.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/UI/Input/DropDown.ts b/UI/Input/DropDown.ts index b9fb6a3d3..493c9bec7 100644 --- a/UI/Input/DropDown.ts +++ b/UI/Input/DropDown.ts @@ -13,6 +13,11 @@ export class DropDown extends InputElement { private readonly _value: UIEventSource; private readonly _values: { value: T; shown: string | BaseUIElement }[]; + /** + * + * const dropdown = new DropDown("test",[{value: 42, shown: "the answer"}]) + * dropdown.GetValue().data // => 42 + */ constructor(label: string | BaseUIElement, values: { value: T, shown: string | BaseUIElement }[], value: UIEventSource = undefined, @@ -21,7 +26,7 @@ export class DropDown extends InputElement { } ) { super(); - value = value ?? new UIEventSource(undefined) + value = value ?? new UIEventSource(values[0].value) this._value = value this._values = values; if (values.length <= 1) { @@ -63,7 +68,7 @@ export class DropDown extends InputElement { select.onchange = (() => { - var index = select.selectedIndex; + const index = select.selectedIndex; value.setData(values[index].value); });