Skip to content

no keyboard events with Material-UI's Modal/Dialog #32

Description

@stt

For whatever reason react-keyboard-event-handler doesn't appear to work with https://material-ui.com/api/dialog/
It works outside of it but in a Dialog, nothing.

For anyone googling about the subject, on hindsight realised I was being dumb spending time debugging when all I needed was

  useEffect(() => {
    const handleKey = (e) => {
      if (e.key >= 1 && e.key < 10) setStars(Number(e.key))
    }
    window.addEventListener('keydown', handleKey)
    return () => window.removeEventListener('keydown', handleKey)
  },[])

(of course unmount the component to unregister listener instead of just hiding it)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions