Skip to content

Commit 61d812a

Browse files
Merge pull request #36 from Travelopia/fix/35-mutli-select-duplicate-event-listeners
Fix duplicate event listeners in multi-select component
2 parents 0282694 + b62099f commit 61d812a

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@travelopia/web-components",
3-
"version": "0.5.15",
3+
"version": "0.5.16",
44
"description": "Accessible web components for the modern web",
55
"files": [
66
"dist"

src/multi-select/tp-multi-select-field.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,23 @@ import { TPMultiSelectElement } from './tp-multi-select';
77
* TP Multi Select Field.
88
*/
99
export class TPMultiSelectFieldElement extends HTMLElement {
10+
/**
11+
* Properties.
12+
*/
13+
private initialized: boolean = false;
14+
1015
/**
1116
* Connected callback.
1217
*/
1318
connectedCallback(): void {
19+
// Return early if already initialized.
20+
if ( true === this.initialized ) {
21+
return;
22+
}
23+
24+
// Set initialized flag to true.
25+
this.initialized = true;
26+
1427
this.addEventListener( 'click', this.toggleOpen.bind( this ) );
1528
}
1629

src/multi-select/tp-multi-select-option.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,23 @@ import { TPMultiSelectElement } from './tp-multi-select';
77
* TP Multi Select Option.
88
*/
99
export class TPMultiSelectOptionElement extends HTMLElement {
10+
/**
11+
* Properties.
12+
*/
13+
private initialized: boolean = false;
14+
1015
/**
1116
* Connected callback.
1217
*/
1318
connectedCallback(): void {
19+
// Return early if already initialized.
20+
if ( true === this.initialized ) {
21+
return;
22+
}
23+
24+
// Set initialized flag to true.
25+
this.initialized = true;
26+
1427
this.addEventListener( 'click', this.toggle.bind( this ) );
1528
}
1629

0 commit comments

Comments
 (0)