Add declarataive event handlers.
Now inside the <template> of a SkyElement you can use on-eventName="method" on any element to add event listeners. For example you can write <sky-button on-click="handleClick"> and then define handleClick(event) on the element class that contains the button. In adding this and tests I also realized that property bindings were not setup on the initial call to bind(), which is now fixed in this patch (See change to Node.prototype.bind). R=eseidel@google.com, rafaelw@chromium.org Review URL: https://codereview.chromium.org/812713005
This commit is contained in:
parent
ea93d43e64
commit
e1e7110716
@ -16,8 +16,9 @@
|
||||
</style>
|
||||
|
||||
<sky-box title='Buttons'>
|
||||
<sky-button id='button'>Button</sky-button>
|
||||
<sky-button id='button' on-click='handleClick'>Button</sky-button>
|
||||
<div>highlight: {{ myButton.highlight }}</div>
|
||||
<div>clickCount: {{ clickCount }}</div>
|
||||
</sky-box>
|
||||
|
||||
<sky-box title='Checkboxes'>
|
||||
@ -47,6 +48,10 @@ module.exports = class extends SkyElement {
|
||||
attached() {
|
||||
this.myButton = this.shadowRoot.getElementById('button');
|
||||
this.myCheckbox = this.shadowRoot.getElementById('checkbox');
|
||||
this.clickCount = 0;
|
||||
}
|
||||
handleClick(event) {
|
||||
this.clickCount++;
|
||||
}
|
||||
}.register();
|
||||
</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user