-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfire-event.html
59 lines (52 loc) · 1.73 KB
/
fire-event.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<link rel="import" href="../polymer/polymer-element.html">
<dom-module id="fire-event">
<script>
/**
* `fire-event`
* Test examples
*
* @customElement
* @polymer
* @demo demo/fire-event.html
*/
class FireEvent extends Polymer.Element {
static get is() { return 'fire-event'; }
static get template() {
return Polymer.html`
<style>
:host {
display: block;
}
</style>
<!-- on-click is not the same as onclick -->
<button on-click="_fireEvent">Fire Event!!!</button>
<button id="MyButtonListener">Fire Event from a listener (you can focus me and then press space)!!!</button>
`;
}
connectedCallback() {
super.connectedCallback();
this.shadowRoot.querySelector('#MyButtonListener').addEventListener('keydown', this._fireEventWithDetails);
}
disconnectedCallback() {
super.disconnectedCallback();
this.shadowRoot.querySelector('#MyButtonListener').removeEventListener('keydown', this._fireEventWithDetails);
}
_fireEvent() {
this.dispatchEvent(new CustomEvent('my-fired-event', {
bubbles: true,
composed: true,
}));
}
_fireEventWithDetails() {
this.dispatchEvent(new CustomEvent('my-fired-event', {
bubbles: true,
composed: true,
detail: {
myDetail: true,
},
}));
}
}
window.customElements.define(FireEvent.is, FireEvent);
</script>
</dom-module>