MapComplete/src/UI/Base/Dropdown.svelte

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
751 B
Svelte
Raw Normal View History

2023-03-28 05:13:48 +02:00
<script lang="ts">
2023-12-01 15:23:28 +01:00
import { UIEventSource } from "../../Logic/UIEventSource.js"
2023-03-28 05:13:48 +02:00
export let value: UIEventSource<any>
let i: any = value.data
2023-12-01 15:23:28 +01:00
let htmlElement: HTMLSelectElement
function selectAppropriateValue() {
if (!htmlElement) {
return
}
const v = value.data
for (let option of htmlElement.getElementsByTagName("option")) {
2023-12-01 15:23:28 +01:00
if (option.value === v) {
option.selected = true
return
}
}
}
2023-12-01 15:23:28 +01:00
value.addCallbackD(() => selectAppropriateValue())
$: {
2023-12-01 15:23:28 +01:00
if (htmlElement) {
selectAppropriateValue()
}
}
2023-12-02 01:46:50 +01:00
export let cls : string = undefined
2023-03-28 05:13:48 +02:00
</script>
2023-12-02 01:46:50 +01:00
<select class={cls} bind:this={htmlElement} on:change={(e) => {value.setData(e.srcElement.value)}}>
<slot />
2023-03-28 05:13:48 +02:00
</select>