DEV Community

Discussion on: LitElement: using web components

Collapse
 
nathancourtney profile image
nathan-courtney

This is great! One question, how would you pass in multiple parameters? Would it look something like this?

updateChecked({event, param2, param3}) {
      console.log(event, param2, param3);
      console.log((this.checked = event.target.checked));
    }

    render() {
      return html`
        <label class="md_switch">
          <input
            @change="${e =>
              this.updateChecked({
                event: e,
                param2: this.param2,
                param3: this.param3
              })}"
            ?checked="${this.checked}"
            ?disabled="${this.disabled}"
            type="checkbox"
          />
          <span class="md_switch__toggle"></span>
          <slot></slot>
        </label>
      `;
    }
Collapse
 
link2twenty profile image
Andrew Bone

I don't think you'd ever want to add more parameters with an event. Looking at your example the params were attached to this anyway so we can just get them with the function.

updateChecked(e) {
  console.log(e, this.param2, this.param3);
}

render() {
  return html`
    <label class="md_switch">
      <input
        @change="${this.updateChecked}"
        ?checked="${this.checked}"
        ?disabled="${this.disabled}"
        type="checkbox"
        />
      <span class="md_switch__toggle"></span>
      <slot></slot>
    </label>
  `;
}