Merge pull request #407 from weaseldotro/patch-1

fix(RadioButtonGroup): make selected prop reactive
This commit is contained in:
Eric Liu 2020-11-22 09:14:42 -08:00 committed by GitHub
commit b10b4a4a10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,7 +26,7 @@
*/ */
export let id = undefined; export let id = undefined;
import { createEventDispatcher, setContext } from "svelte"; import { beforeUpdate, createEventDispatcher, onMount, setContext } from "svelte";
import { writable } from "svelte/store"; import { writable } from "svelte/store";
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
@ -40,11 +40,21 @@
} }
}, },
update: (value) => { update: (value) => {
selectedValue.set(value); selected = value;
}, },
}); });
$: selected = $selectedValue; onMount(() => {
$selectedValue = selected
})
beforeUpdate(() => {
$selectedValue = selected
})
$: $selectedValue, (() => {
selected = $selectedValue
})
$: dispatch("change", $selectedValue); $: dispatch("change", $selectedValue);
</script> </script>