Skip to content

Commit aea6ae5

Browse files
TOP-10-DEVswyxio
andcommitted
Added event types and their descriptions (#402)
* Added form types and their descriptions I was looking for a complete list of form types and couldn't find any anywhere. I went through the source code and extracted these with adding some description to them, either using MDN's description or some other website explanation. * Apply suggestions from code review Co-authored-by: swyx <[email protected]>
1 parent a7c6e98 commit aea6ae5

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

docs/basic/getting-started/forms-and-events.md

+39
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,42 @@ If you don't quite care about the type of the event, you can just use React.Synt
9898
[View in the TypeScript Playground](https://www.typescriptlang.org/play/?jsx=2#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wFgAoCtCAOwGctoRlM4BeRYmAOgFc6kLABQBKClVoM4AMSbs4o9gD4FFOHAA8mJmrhFMbAN7aozJJgC+u2gGVeAIxDAYRoUgBcndDxsBPGjAAFkgwwGgAogBuSAEiynCGuupI3GBE0QEAIuYovAA2MKIA3Elw1PTwMChQAOYh8ilVtfUodHAwvmBIEKyN1XXwAGQJpckgKMB5noZwkSh5vB5wDFDANDVwFiXk6rtwYK10AO7QACbTs-OLnitrG1ulDzu75VJI45PyTQPc7xN53DmCyQRTgAHowe1Okg0ME0ABrOgAQlKr3gBzoxzOX36IVShxOUFOgKuIPBkI6XVhMMRKOe6ghcBCaG4rN0Fis5CUug0p2AkW59M0eRQ9iQeUFe3U4Q+U1GmjWYF4lWhbAARH9Jmq4DQUCAkOrNXltWDJbsNGCRWKJTywXyBTz7Wb1BoreLnbsAAoEs7ueUaRXKqFddUYrFE7W6-Whn0R8Eei1um3PC1Ox38hOBlUhtV0BxOGDaoGLdUAGQgGzWJrNqYzFAtJhAgpEQA)
9999

100100
Of course, if you're making any sort of significant form, [you should use Formik](https://jaredpalmer.com/formik) or [React Hook Form](https://react-hook-form.com/), which are written in TypeScript.
101+
102+
### List of event types
103+
104+
105+
| Event Type | Description |
106+
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------- |
107+
| AnimationEvent | CSS Animations. |
108+
| ChangeEvent | Changing the value of `<input>`, `<select>` and `<textarea>` element. |
109+
| ClipboardEvent | Using copy, paste and cut events. |
110+
| CompositionEvent | Events that occur due to the user indirectly entering text (e.g. depending on Browser and PC setup, a popup window may appear with additional characters if you e.g. want to type Japanese on a US Keyboard) |
111+
| DragEvent | Drag and drop interaction with a pointer device (e.g. mouse). |
112+
| FocusEvent | Event that occurs when elements gets or loses focus. |
113+
| FormEvent | Event that occurs whenever a form or form element gets/loses focus, a form element value is changed or the form is submitted. |
114+
| InvalidEvent | Fired when validity restrictions of an input fails (e.g `<input type="number" max="10">` and someone would insert number 20). |
115+
| KeyboardEvent | User interaction with the keyboard. Each event describes a single key interaction. |
116+
| MouseEvent | Events that occur due to the user interacting with a pointing device (e.g. mouse) |
117+
| PointerEvent | Events that occur due to user interaction with a variety pointing of devices such as mouse, pen/stylus, a touchscreen and which also supports multi-touch. Unless you develop for older browsers (IE10 or Safari 12), pointer events are recommended. Extends UIEvent. |
118+
| TouchEvent | Events that occur due to the user interacting with a touch device. Extends UIEvent. |
119+
| TransitionEvent | CSS Transition. Not fully browser supported. Extends UIEvent |
120+
| UIEvent | Base Event for Mouse, Touch and Pointer events. |
121+
| WheelEvent | Scrolling on a mouse wheel or similar input device. (Note: `wheel` event should not be confused with the `scroll` event) |
122+
| SyntheticEvent | The base event for all above events. Should be used when unsure about event type |
123+
124+
<details>
125+
<summary>
126+
127+
**What about `InputEvent`?**
128+
129+
</summary>
130+
131+
You've probably noticed that there is no `InputEvent`. This is because it is not supported by Typescript as the event itself has no fully browser support and may behave differently in different browsers. You can use `KeyboardEvent` instead.
132+
133+
Sources:
134+
135+
- https://github.com/microsoft/TypeScript/issues/29441
136+
- https://developer.mozilla.org/en-US/docs/Web/API/InputEvent
137+
- https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event
138+
139+
</details>

0 commit comments

Comments
 (0)