1
0
Fork 0
mirror of synced 2024-08-15 18:11:40 +12:00

Fix fancy select not correctly displaying the label for the selected value

This commit is contained in:
Andrew Kingston 2023-01-25 14:11:33 +00:00
parent 88d0ab837d
commit 2b8525ef4e

View file

@ -21,6 +21,7 @@
let wrapper
$: placeholder = !value
$: selectedLabel = getSelectedLabel(value)
const extractProperty = (value, property) => {
if (value && typeof value === "object") {
@ -37,6 +38,17 @@
}
open = false
}
const getSelectedLabel = value => {
if (!value || !options?.length) {
return ""
}
const selectedOption = options.find(x => getOptionValue(x) === value)
if (!selectedOption) {
return value
}
return getOptionLabel(selectedOption)
}
</script>
<FancyField
@ -53,7 +65,7 @@
{/if}
<div class="value" class:placeholder>
{value || ""}
{selectedLabel || ""}
</div>
<div class="arrow">