--- id: events title: SyntheticEvent permalink: docs/events.html layout: docs category: Reference --- This reference guide documents the `SyntheticEvent` wrapper that forms part of React's Event System. See the [Handling Events](/docs/handling-events.html) guide to learn more. ## Overview {#overview} Your event handlers will be passed instances of `SyntheticEvent`, a cross-browser wrapper around the browser's native event. It has the same interface as the browser's native event, including `stopPropagation()` and `preventDefault()`, except the events work identically across all browsers. If you find that you need the underlying browser event for some reason, simply use the `nativeEvent` attribute to get it. The synthetic events are different from, and do not map directly to, the browser's native events. For example in `onMouseLeave` `event.nativeEvent` will point to a `mouseout` event. The specific mapping is not part of the public API and may change at any time. Every `SyntheticEvent` object has the following attributes: ```javascript boolean bubbles boolean cancelable DOMEventTarget currentTarget boolean defaultPrevented number eventPhase boolean isTrusted DOMEvent nativeEvent void preventDefault() boolean isDefaultPrevented() void stopPropagation() boolean isPropagationStopped() void persist() DOMEventTarget target number timeStamp string type ``` > Note: > > As of v17, `e.persist()` doesn't do anything because the `SyntheticEvent` is no longer [pooled](/docs/legacy-event-pooling.html). > Note: > > As of v0.14, returning `false` from an event handler will no longer stop event propagation. Instead, `e.stopPropagation()` or `e.preventDefault()` should be triggered manually, as appropriate. ## Supported Events {#supported-events} React normalizes events so that they have consistent properties across different browsers. The event handlers below are triggered by an event in the bubbling phase. To register an event handler for the capture phase, append `Capture` to the event name; for example, instead of using `onClick`, you would use `onClickCapture` to handle the click event in the capture phase. - [Clipboard Events](#clipboard-events) - [Composition Events](#composition-events) - [Keyboard Events](#keyboard-events) - [Focus Events](#focus-events) - [Form Events](#form-events) - [Generic Events](#generic-events) - [Mouse Events](#mouse-events) - [Pointer Events](#pointer-events) - [Selection Events](#selection-events) - [Touch Events](#touch-events) - [UI Events](#ui-events) - [Wheel Events](#wheel-events) - [Media Events](#media-events) - [Image Events](#image-events) - [Animation Events](#animation-events) - [Transition Events](#transition-events) - [Other Events](#other-events) * * * ## Reference {#reference} ### Clipboard Events {#clipboard-events} Event names: ``` onCopy onCut onPaste ``` Properties: ```javascript DOMDataTransfer clipboardData ``` * * * ### Composition Events {#composition-events} Event names: ``` onCompositionEnd onCompositionStart onCompositionUpdate ``` Properties: ```javascript string data ``` * * * ### Keyboard Events {#keyboard-events} Event names: ``` onKeyDown onKeyPress onKeyUp ``` Properties: ```javascript boolean altKey number charCode boolean ctrlKey boolean getModifierState(key) string key number keyCode string locale number location boolean metaKey boolean repeat boolean shiftKey number which ``` The `key` property can take any of the values documented in the [DOM Level 3 Events spec](https://www.w3.org/TR/uievents-key/#named-key-attribute-values). * * * ### Focus Events {#focus-events} Event names: ``` onFocus onBlur ``` These focus events work on all elements in the React DOM, not just form elements. Properties: ```js DOMEventTarget relatedTarget ``` #### onFocus {#onfocus} The `onFocus` event is called when the element (or some element inside of it) receives focus. For example, it's called when the user clicks on a text input. ```javascript function Example() { return ( { console.log('Focused on input'); }} placeholder="onFocus is triggered when you click this input." /> ) } ``` #### onBlur {#onblur} The `onBlur` event handler is called when focus has left the element (or left some element inside of it). For example, it's called when the user clicks outside of a focused text input. ```javascript function Example() { return ( { console.log('Triggered because this input lost focus'); }} placeholder="onBlur is triggered when you click this input and then you click outside of it." /> ) } ``` #### Detecting Focus Entering and Leaving {#detecting-focus-entering-and-leaving} You can use the `currentTarget` and `relatedTarget` to differentiate if the focusing or blurring events originated from _outside_ of the parent element. Here is a demo you can copy and paste that shows how to detect focusing a child, focusing the element itself, and focus entering or leaving the whole subtree. ```javascript function Example() { return (