Skip to main content

oncancel

Description

Fires on click of the Cancel button or when the ESC key is pressed

Usage

oncancel?: (ev: { button?: string; ev: MouseEvent }) => void;

Parameters

The callback of the event takes an object with the following parameter:

  • button – (optional) the value is "cancel" if the event fires on the Cancel button click
  • ev – the native MouseEvent of the click

The event also fires on pressing ESC, the callback function takes a native HTML event object.

Example

<script>
import { Modal, Text, Portal, Button } from "@svar-ui/svelte-core";

let custom1;
function hideAll() {
custom1 = false;
}
</script>

{#if custom1}
<Portal>
<Modal title="Custom Prompt" oncancel={hideAll}>
<Text select={true} focus={true} value="Some" />
</Modal>
</Portal>
{/if}

Related article: Providing the buttons' functionality

Related sample: Messages