Don't trigger selection-changed event if selection didn't change.

This commit is contained in:
trading_peter 2023-09-03 21:31:42 +02:00
parent 1e9ab0e01d
commit 64ba82fc9d
2 changed files with 2 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@tp/tp-multi-toggle", "name": "@tp/tp-multi-toggle",
"version": "1.0.1", "version": "1.1.0",
"description": "", "description": "",
"main": "tp-multi-toggle.js", "main": "tp-multi-toggle.js",
"scripts": { "scripts": {

View File

@ -80,7 +80,7 @@ class TpMultiToggle extends FormElement(LitElement) {
onClick(e) { onClick(e) {
const btn = closest(e.target, 'tp-button', true); const btn = closest(e.target, 'tp-button', true);
if (btn) { if (btn && !btn.hasAttribute('selected')) {
this.querySelectorAll('tp-button').forEach(el => el.removeAttribute('selected')); this.querySelectorAll('tp-button').forEach(el => el.removeAttribute('selected'));
btn.setAttribute('selected', ''); btn.setAttribute('selected', '');
this.dispatchEvent(new CustomEvent('selection-changed', { detail: this.value, bubbles: true, composed: true })); this.dispatchEvent(new CustomEvent('selection-changed', { detail: this.value, bubbles: true, composed: true }));