lit-analyzer icon indicating copy to clipboard operation
lit-analyzer copied to clipboard

Events `cancel` and `close` on <dialog> reported by `no-unknown-event`

Open jrencz opened this issue 3 years ago • 1 comments

Code:

class MyElementWithDialog extends LitElement {
  override render() {
    return html`<dialog
      @click="${this.onDialogClick}"
      @close="${this.onDialogClose}"
      @cancel="${this.onDialogCancel}"
    >Content</dialog>
  }
}

Reports

    Unknown event 'cancel'. Did you mean '@change'?
    6:  @cancel="${this.onDialogCancel}"
    no-unknown-event


    Unknown event 'close'.
    6:  @close="${this.onDialogClose}"
    no-unknown-event

[email protected]

Both events exist and work

  • https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement/close_event
  • https://developer.mozilla.org/en-US/docs/Web/API/HTMLDialogElement/cancel_event

but they don't seem to be known to the tool.

Workaround:

declare global {
  /**
   * @emits cancel
   * @emits close
   */
  interface HTMLDialogElement {}
}

jrencz avatar Nov 01 '22 21:11 jrencz

The same error is raised for the paste event.

didnotwant avatar Feb 13 '25 13:02 didnotwant