Skip to content

Commit

Permalink
Dispatch apply event when applying from MultiSelect (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonmcconnell authored Sep 5, 2024
1 parent 1c0a51c commit 8fb2985
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/polite-rivers-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte-ux': patch
---

Dispatch `apply` event when applying from MultiSelect
10 changes: 9 additions & 1 deletion packages/svelte-ux/src/lib/components/MultiSelect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,17 @@
indeterminate: typeof $indeterminateStore;
original: { selected: MenuOption<TValue>[]; unselected: MenuOption<TValue>[] };
};
apply: {
value: typeof value;
selection: typeof $selection;
indeterminate: typeof $indeterminateStore;
original: { selected: MenuOption<TValue>[]; unselected: MenuOption<TValue>[] };
};
cancel: null;
}>();
export let onApply = async (ctx: {
value: typeof value;
selection: typeof $selection;
indeterminate: typeof $indeterminateStore;
original: { selected: MenuOption<TValue>[]; unselected: MenuOption<TValue>[] };
Expand All @@ -71,12 +78,13 @@
async function applyChange() {
applying = true;
const changeContext = {
value: $selection.selected,
value: $selection.selected as TValue[],
selection: $selection,
indeterminate: $indeterminateStore,
original: { selected: selectedOptions, unselected: unselectedOptions },
};
await onApply(changeContext);
dispatch('apply', changeContext);
applying = false;
onChange();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@
bind:open
on:change={onSelectChange}
on:close={hide}
on:apply
bind:menuOptionsEl
{...menuProps}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
on:cancel
on:change={() => mode !== 'immediate' && close()}
on:change
on:apply
>
<slot name="beforeOptions" slot="beforeOptions" let:selection {selection} />
<slot name="afterOptions" slot="afterOptions" let:selection {selection} />
Expand Down

0 comments on commit 8fb2985

Please sign in to comment.