Skip to content

Commit ad00d1e

Browse files
committed
feat(Selection): Add change event. Resolves #520
1 parent 1f356f9 commit ad00d1e

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

.changeset/brave-chefs-crash.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte-ux': minor
3+
---
4+
5+
feat(Selection): Add `change` event. Resolves #520

packages/svelte-ux/src/lib/components/Selection.svelte

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script lang="ts">
2+
import { createEventDispatcher } from 'svelte';
23
import selectionStore from '../stores/selectionStore.js';
34
45
type T = $$Generic;
@@ -10,6 +11,10 @@
1011
1112
const selection = selectionStore({ initial, all, single, max });
1213
$: $selection.all.set(all);
14+
15+
const dispatch = createEventDispatcher();
16+
17+
$: dispatch('change', { value: $selection.selected });
1318
</script>
1419

1520
<!-- TODO: `<slot {...$selection} />` does not play well with sveld -->

packages/svelte-ux/src/routes/docs/components/Selection/+page.svelte

+20
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,23 @@
127127
selected: {JSON.stringify(selected)}
128128
</Selection>
129129
</Preview>
130+
131+
<h2>change event</h2>
132+
133+
<Preview>
134+
<Selection
135+
let:selected
136+
let:isSelected
137+
let:toggleSelected
138+
on:change={(e) => console.log(e.detail)}
139+
>
140+
{#each data as d}
141+
<div>
142+
<Checkbox checked={isSelected(d.id)} on:change={() => toggleSelected(d.id)}>
143+
{d.id}
144+
</Checkbox>
145+
</div>
146+
{/each}
147+
selected: {JSON.stringify(selected)}
148+
</Selection>
149+
</Preview>

0 commit comments

Comments
 (0)