Skip to content
This repository was archived by the owner on Feb 1, 2026. It is now read-only.

Commit 5536ad5

Browse files
committed
fix: select control now respects option value type
1 parent b34e795 commit 5536ad5

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

playground/src/pages/controls/SelectControlDemo.vue

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,11 @@ const { toneMapping } = useControls({
1717
],
1818
},
1919
})
20-
21-
const formattedToneMapping = computed(() => {
22-
return Number(toneMapping.value)
23-
})
2420
</script>
2521

2622
<template>
2723
<TresLeches />
28-
<TresCanvas clear-color="#82DBC5" :tone-mapping="formattedToneMapping">
24+
<TresCanvas clear-color="#82DBC5" :tone-mapping="toneMapping">
2925
<TresPerspectiveCamera :position="[4, 4, 4]" />
3026
<Suspense>
3127
<Environment preset="sunset" :background="true" />

src/components/SelectControl.vue

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
<script setup lang="ts">
2-
import type { LechesControl } from '../types'
2+
import type { LechesControl, LechesSelectOption } from '../types'
33
import ControlLabel from './ControlLabel.vue'
44
5-
defineProps<{
5+
const props = defineProps<{
66
label: string
77
control: LechesControl
88
}>()
99
1010
const emit = defineEmits(['change'])
1111
1212
function onChange(event: Event) {
13-
emit('change', (event.target as HTMLSelectElement).value)
13+
const selectedValue = (event.target as HTMLSelectElement).value
14+
15+
// Find the matching option to preserve the original type
16+
const selectedOption = props.control.options?.find((option: LechesSelectOption) =>
17+
String(option.value) === selectedValue,
18+
)
19+
20+
// Use the original value with its correct type
21+
emit('change', selectedOption?.value ?? selectedValue)
1422
}
1523
</script>
1624

@@ -22,14 +30,14 @@ function onChange(event: Event) {
2230
/>
2331
<select
2432
:id="control.uniqueKey"
25-
:value="control.value"
33+
:value="String(control.value)"
2634
class="tl-leches-input tl-w-2/3"
2735
@change="onChange"
2836
>
2937
<option
3038
v-for="option in control.options"
31-
:key="option.value"
32-
:value="option.value"
39+
:key="String(option.value)"
40+
:value="String(option.value)"
3341
>
3442
{{ option.text }}
3543
</option>

0 commit comments

Comments
 (0)