Skip to content

QUESTION: How to do keydown event on a btn? #29

@liketoeatcheese

Description

@liketoeatcheese

Hey mate,

First of all, what a genius plugin!!!

I'm trying to get rid of a bunch of my js files with Surreal. How would I do me().on("multipleevents?"), like click and keydown (Esc) at the same time? For example, how would I achieve something like this but keep the locality of behaviour effect?

<button id="cancelBtnDrawerForm"/>
const cancelBtnDrawerForm = document.getElementById('cancelBtnDrawerForm')
const cancelDrawerForm = () => {
  form.classList.remove('show')
  bodyWrapper.classList.remove('scaled')
  body.classList.remove('scaled')
  setTimeout(() => {
    form.style.display = 'none'
    backdrop.style.display = 'none'
  }, 200)
}

cancelBtnDrawerForm.addEventListener('click', cancelDrawerForm)
document.addEventListener('keydown', (event) => {
  if (event.key === 'Escape') {
    cancelDrawerForm();
  }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions