feat(toolbar-batch-actions): dispatch cancelable on:cancel event (#1441)

Closes #1438
This commit is contained in:
naegelin 2022-08-14 21:09:40 +02:00 committed by GitHub
commit 06777ba803
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 6 deletions

View file

@ -1,4 +1,8 @@
<script>
/**
* @event {null} cancel
*/
/**
* Override the total items selected text
* @type {(totalSelected: number) => string}
@ -12,14 +16,26 @@
*/
export let active = false;
import { onMount, getContext } from "svelte";
import { onMount, getContext, createEventDispatcher } from "svelte";
import Button from "../Button/Button.svelte";
let batchSelectedIds = [];
$: showActions = batchSelectedIds.length > 0 || active;
const dispatch = createEventDispatcher();
const ctx = getContext("DataTable");
function cancel() {
const shouldContinue = dispatch("cancel", null, { cancelable: true });
if (shouldContinue) {
ctx.resetSelectedRowIds();
}
}
$: showActions = batchSelectedIds.length > 0 || active;
const unsubscribe = ctx.batchSelectedIds.subscribe((value) => {
batchSelectedIds = value;
});
@ -55,7 +71,7 @@
<Button
class="bx--batch-summary__cancel"
tabindex="{showActions ? '0' : '-1'}"
on:click="{ctx.resetSelectedRowIds}"
on:click="{cancel}"
>
<slot name="cancel">Cancel</slot>
</Button>