mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 11:36:36 +00:00
Fix binding bug
This commit is contained in:
parent
80f49f6a8f
commit
de1c2d00eb
6 changed files with 65 additions and 16 deletions
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue