-
Notifications
You must be signed in to change notification settings - Fork 0
DOM events
George Treviranus edited this page Mar 25, 2022
·
8 revisions
Event listeners are vanilla javascript in Bulba. Bind the handler and create an event listener normally.
Wait until onMount()
to query and set an event listener to your component elements.
constructor() {
this.handleClick = this.handleClick.bind(this)
}
handleClick() {/**/}
onMount() {
this.button = this.shadowRoot.querySelector(".my-button")
this.button.addEventListener("click", this.handleClick)
}
onUnmount() {
this.button.removeEventListener("click", this.handleClick)
}
Similar to the template example, but you can bind right to the JSX node in question.
constructor() {
this.handleClick = this.handleClick.bind(this)
}
handleClick() {/**/}
render() {
return (
<button on-click={this.handleClick}>Click me</button>
)
}