1
0
Fork 0
mirror of synced 2024-07-06 15:00:49 +12:00

Fix bug in checkboxgroup due to reassignment of value prop

This commit is contained in:
Andrew Kingston 2023-07-18 16:47:43 +01:00
parent f10da70233
commit bada641262
2 changed files with 13 additions and 12 deletions

View file

@ -12,23 +12,24 @@
export let getOptionValue = option => option
const dispatch = createEventDispatcher()
const onChange = e => {
let tempValue = value
let isChecked = e.target.checked
if (!tempValue.includes(e.target.value) && isChecked) {
tempValue.push(e.target.value)
const optionValue = e.target.value
if (e.target.checked && !value.includes(optionValue)) {
dispatch("change", [...value, optionValue])
} else {
dispatch(
"change",
value.filter(x => x !== optionValue)
)
}
value = tempValue
dispatch(
"change",
tempValue.filter(val => val !== e.target.value || isChecked)
)
}
</script>
<div class={`spectrum-FieldGroup spectrum-FieldGroup--${direction}`}>
{#if options && Array.isArray(options)}
{#each options as option}
{@const optionValue = getOptionValue(option)}
<div
title={getOptionLabel(option)}
class="spectrum-Checkbox spectrum-FieldGroup-item"
@ -39,11 +40,11 @@
>
<input
on:change={onChange}
value={getOptionValue(option)}
type="checkbox"
class="spectrum-Checkbox-input"
value={optionValue}
checked={value.includes(optionValue)}
{disabled}
checked={value.includes(getOptionValue(option))}
/>
<span class="spectrum-Checkbox-box">
<svg

View file

@ -38,7 +38,7 @@
return []
}
if (Array.isArray(values)) {
return values
return values.slice()
}
return values.split(",").map(value => value.trim())
}