hono icon indicating copy to clipboard operation
hono copied to clipboard

Types for Events

Open yusukebe opened this issue 1 year ago • 1 comments

What is the feature you are proposing?

We want to have React-like TypeScript types for HTML events like a React.ChangeEvent.

For example, the simple one could be implemented as the following:

interface ChangeEvent<T = Element> {
  target: EventTarget & T
}

const Input = (
  <input
    type="checkbox"
    onChange={(e: ChangeEvent<HTMLInputElement>) => setFoo(e.target.checked)}
  />
)

There are some event types other than React.ChangeEvent:

type Props = {
  onClick: (event: React.MouseEvent<HTMLInputElement>) => void
  onChange: (event: React.ChangeEvent<HTMLInputElement>) => void
  onKeypress: (event: React.KeyboardEvent<HTMLInputElement>) => void
  onBlur: (event: React.FocusEvent<HTMLInputElement>) => void
  onFocus: (event: React.FocusEvent<HTMLInputElement>) => void
  onSubmit: (event: React.FormEvent<HTMLFormElement>) => void
  onClickDiv: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void
}

yusukebe avatar Feb 02 '24 23:02 yusukebe

It will be tough but, maybe we can do it.

Screenshot 2024-02-04 at 0 39 16 Screenshot 2024-02-04 at 0 39 45

yusukebe avatar Feb 03 '24 15:02 yusukebe

Fixed!

yusukebe avatar Mar 01 '24 13:03 yusukebe