Skip to content

Commit 16492df

Browse files
committed
Add event support to Tag.
1 parent 0657957 commit 16492df

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

ts/html/Tag.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import UiComponent from '../UiComponent';
33
export default class Tag implements UiComponent {
44
constructor(private _name: string,
55
private _body?: UiComponent,
6-
private _attrs?: {[key: string]: any}) {
6+
private _attrs?: {[key: string]: any},
7+
private _events?: {[key: string]: EventListenerOrEventListenerObject}) {
78
}
89

910
appendTo(entry: HTMLElement | null): void {
@@ -21,6 +22,12 @@ export default class Tag implements UiComponent {
2122
}
2223
}
2324

25+
if (this._events) {
26+
for (let eventKey in this._events) {
27+
element.addEventListener(eventKey, this._events[eventKey])
28+
}
29+
}
30+
2431
if (this._body) {
2532
this._body.appendTo(element);
2633
}

0 commit comments

Comments
 (0)