Home > Back-end >  Change event listener for `SlideToggle` of Skeleton (Svelte UI kit)
Change event listener for `SlideToggle` of Skeleton (Svelte UI kit)

Time:11-17

Using SlideToggle of Skeleton, I am creating a toggle switch like this.

<script lang="ts">
    import { SlideToggle } from '@brainandbones/skeleton';
    let is_checked: boolean = false;
</script>

<div >
    <SlideToggle bind:checked={is_monitoring}>{is_checked ? 'Activated' : 'Disabled'}</SlideToggle>
</div>

How can I get on-change event instead of polling is_checked status manually?

CodePudding user response:

You can bind a change event to the toggle. This event listener will get forwarded to the underlying element in the slider.

<script lang="ts">
    import { SlideToggle } from '@brainandbones/skeleton';

    let handleOnChange = (e) => {
       // your subroutine goes here
    }
</script>

<SlideToggle on:change={handleOnChange}>Label</SlideToggle>

More info under the 'events' tab on enter image description here

  • Related