From a9f07a561410ab0fa708804f65281014a5fb918d Mon Sep 17 00:00:00 2001 From: Peter Kaske Date: Tue, 5 Apr 2022 14:57:14 +0200 Subject: [PATCH] Add toggle event and change when checked-change event is fired. --- package.json | 2 +- tp-checkbox.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 594a071..a899a61 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tp/tp-checkbox", - "version": "1.0.2", + "version": "1.0.3", "description": "", "main": "tp-checkbox.js", "scripts": { diff --git a/tp-checkbox.js b/tp-checkbox.js index e458169..dc6c805 100644 --- a/tp-checkbox.js +++ b/tp-checkbox.js @@ -90,7 +90,13 @@ class TpCheckbox extends Inert(ControlState(FormElement(LitElement))) { toggle() { this.checked = !this.checked; - this.dispatchEvent(new CustomEvent('checked-changed', { detail: this.checked, bubbles: true, composed: true })); + this.dispatchEvent(new CustomEvent('toggled', { detail: this.checked, bubbles: true, composed: true })); + } + + updated(changes) { + if (changes.has('checked')) { + this.dispatchEvent(new CustomEvent('checked-changed', { detail: this.checked, bubbles: true, composed: true })); + } } get value() {