mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 19:46:36 +00:00
cancelable event
This commit is contained in:
parent
87ed2b4782
commit
e5ec362b26
4 changed files with 21 additions and 19 deletions
|
@ -4435,7 +4435,9 @@ None.
|
|||
|
||||
### Events
|
||||
|
||||
None.
|
||||
| Event name | Type | Detail |
|
||||
| :--------- | :--------- | :---------------- |
|
||||
| cancel | dispatched | <code>null</code> |
|
||||
|
||||
## `ToolbarContent`
|
||||
|
||||
|
|
|
@ -13680,7 +13680,7 @@
|
|||
"slot_props": "{}"
|
||||
}
|
||||
],
|
||||
"events": [],
|
||||
"events": [{ "type": "dispatched", "name": "cancel", "detail": "null" }],
|
||||
"typedefs": [],
|
||||
"rest_props": { "type": "Element", "name": "div" }
|
||||
},
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
<script>
|
||||
/**
|
||||
* @event {null} cancel
|
||||
*/
|
||||
|
||||
/**
|
||||
* Override the total items selected text
|
||||
* @type {(totalSelected: number) => string}
|
||||
|
@ -6,29 +10,25 @@
|
|||
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 { onMount, getContext, createEventDispatcher } from "svelte";
|
||||
import Button from "../Button/Button.svelte";
|
||||
|
||||
let batchSelectedIds = [];
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
$: showActions = batchSelectedIds.length > 0;
|
||||
|
||||
const ctx = getContext("DataTable");
|
||||
|
||||
$: cancelClick = () => {
|
||||
if (typeof cancel === "function") {
|
||||
cancel();
|
||||
} else {
|
||||
ctx.resetSelectedRowIds()
|
||||
|
||||
function cancel() {
|
||||
const shouldContinue = dispatch("cancel", null, { cancelable: true });
|
||||
|
||||
if (shouldContinue) {
|
||||
ctx.resetSelectedRowIds();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
const unsubscribe = ctx.batchSelectedIds.subscribe((value) => {
|
||||
batchSelectedIds = value;
|
||||
});
|
||||
|
@ -64,7 +64,7 @@
|
|||
<Button
|
||||
class="bx--batch-summary__cancel"
|
||||
tabindex="{showActions ? '0' : '-1'}"
|
||||
on:click="{cancelClick}"
|
||||
on:click="{cancel}"
|
||||
>
|
||||
<slot name="cancel">Cancel</slot>
|
||||
</Button>
|
||||
|
|
|
@ -12,6 +12,6 @@ export interface ToolbarBatchActionsProps
|
|||
|
||||
export default class ToolbarBatchActions extends SvelteComponentTyped<
|
||||
ToolbarBatchActionsProps,
|
||||
{},
|
||||
{ cancel: CustomEvent<null> },
|
||||
{ default: {}; cancel: {} }
|
||||
> {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue