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
702 B
Svelte
Raw Normal View History

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