Fix binding bug

This commit is contained in:
Richard O'flynn 2020-12-01 16:45:44 +00:00
commit de1c2d00eb
6 changed files with 65 additions and 16 deletions

View file

@ -32,9 +32,13 @@
import { getContext } from "svelte";
import CheckmarkFilled16 from "carbon-icons-svelte/lib/CheckmarkFilled16";
const { update, selectedValues } = getContext("SelectableTileGroup");
const { update, selectedValues, _light } = getContext("SelectableTileGroup");
update({ value, selected });
if (selected) {
update({ value, selected });
}
light = light || _light;
$: selected = $selectedValues.indexOf(value) > -1;
</script>

View file

@ -5,9 +5,15 @@
*/
export let selectedValues = [];
/** Set to `true` to disable the tile group */
export let disabled = false;
/** Specify the legend text */
export let legend = "";
/** Set to `true` to enable the light variant throughout the group */
export let light = false;
import { createEventDispatcher, setContext } from "svelte";
import { writable } from "svelte/store";
@ -15,6 +21,7 @@
const _selectedValues = writable(selectedValues);
setContext("SelectableTileGroup", {
_light: light,
selectedValues: _selectedValues,
update: ({ selected, value }) =>
_selectedValues.update((_) => {
@ -29,11 +36,15 @@
$: dispatch("select", $_selectedValues);
</script>
<fieldset class:bx--tile-group="{true}" {...$$restProps}>
<fieldset disabled="{disabled}" class:bx--tile-group="{true}" {...$$restProps}>
{#if legend}
<legend class:bx--label="{true}">{legend}</legend>
{/if}
<div>
<div
role="group"
aria-label="{$$props['aria-label'] || 'Selectable tiles'}"
data-selected="{selectedValues}"
>
<slot />
</div>
</fieldset>