From 164ed230f8be1b946cdf956f577726e01e26c0f5 Mon Sep 17 00:00:00 2001 From: Christoph Reiter <reiter.christoph@gmail.com> Date: Tue, 26 May 2020 11:27:39 +0200 Subject: [PATCH] textswitch: also emit a change event if the user clicks the same button again Let the user of the component handle the duplicate change events --- src/textswitch.js | 14 +++++++++++--- src/vpu-qualified-signature-pdf-upload.js | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/textswitch.js b/src/textswitch.js index f3503f9..7e025d2 100644 --- a/src/textswitch.js +++ b/src/textswitch.js @@ -8,11 +8,11 @@ const BUTTON2 = "button2"; * Attributes: * value1/value2: The values of the buttons * name1/name2: The names of the buttons - * name: Tshe active name + * name: The active name * disabled: Disable the switch * * Events: - * change: emitted when the active name changes + * change: emitted when the active name changes or the same button is clicked again * * Example: * <my-tag name="one" name1="one" name2="two" value1="One", value2="Two"></my-tag> @@ -87,7 +87,15 @@ export class TextSwitch extends LitElement { render() { const onClick = function (e) { - this._active = e.target.id; + let new_id = e.target.id; + if (new_id === this._active) { + const event = new CustomEvent("change", { + bubbles: true, + cancelable: false, + }); + this.dispatchEvent(event); + } + this._active = new_id; }; return html` diff --git a/src/vpu-qualified-signature-pdf-upload.js b/src/vpu-qualified-signature-pdf-upload.js index 5b7df19..a6f21b8 100644 --- a/src/vpu-qualified-signature-pdf-upload.js +++ b/src/vpu-qualified-signature-pdf-upload.js @@ -673,7 +673,7 @@ class QualifiedSignaturePdfUpload extends ScopedElementsMixin(VPUSignatureLitEle value1="${i18n.t('qualified-pdf-upload.positioning-automatic')}" value2="${i18n.t('qualified-pdf-upload.positioning-manual')}" ?disabled="${this.signingProcessEnabled}" - @click=${ (e) => this.queuePlacementSwitch(id, e.target.name) }></vpu-textswitch> + @change=${ (e) => this.queuePlacementSwitch(id, e.target.name) }></vpu-textswitch> </div> </div> `); -- GitLab