From 87ed2b47823a9f94ef1d100ae94e7bea5cd95df5 Mon Sep 17 00:00:00 2001 From: naegelin Date: Thu, 11 Aug 2022 14:07:28 -0400 Subject: [PATCH] feat(ToolbarBatchActions): Override cancel button Fixes #1438. Give the user the ability to override the functionality of the cancel button by passing in their own function. If no override is provided, the existing functionality of reseting selected row ids is preserved. Example implementation: ``` {console.log("User clicked cancel!")}}> ... ``` --- src/DataTable/ToolbarBatchActions.svelte | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/DataTable/ToolbarBatchActions.svelte b/src/DataTable/ToolbarBatchActions.svelte index eaee6f82..4cbcc79a 100644 --- a/src/DataTable/ToolbarBatchActions.svelte +++ b/src/DataTable/ToolbarBatchActions.svelte @@ -6,6 +6,12 @@ export let formatTotalSelected = (totalSelected) => `${totalSelected} item${totalSelected === 1 ? "" : "s"} selected`; + /** + * Override the default behavior of the cancel button + * @type {function} + */ + export let cancel ; + import { onMount, getContext } from "svelte"; import Button from "../Button/Button.svelte"; @@ -14,6 +20,15 @@ $: showActions = batchSelectedIds.length > 0; const ctx = getContext("DataTable"); + + $: cancelClick = () => { + if (typeof cancel === "function") { + cancel(); + } else { + ctx.resetSelectedRowIds() + } + }; + const unsubscribe = ctx.batchSelectedIds.subscribe((value) => { batchSelectedIds = value; }); @@ -49,7 +64,7 @@