Skip to content

Commit

Permalink
Added disabled canvas events api to documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreylanters committed Jan 6, 2023
1 parent 76ed5a2 commit f693c58
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
38 changes: 38 additions & 0 deletions documentation/docs/api/disabled-canvas-events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Disabled Canvas Events

Overwrites the default disabled canvas events.

## Type Definition

```tsx title="Type Definition"
<Unity disabledCanvasEvents={string[]} />
```

## Implementation

> By default Unity disables the `contextmenu` and `dragstart` events on the canvas element. This is done to prevent the user from right clicking on the canvas and dragging the page while interacting with the Unity Application. Note that by setting the `disabledCanvasEvents` property you'll override the default values. If you don't want this to happen, you'll need to add events these to the array.
## Example Usage​

A basic implementation could look something like this. In the following example overwrite the default values and disable the `dragstart` and `scroll` events. This will also allow the user to right click on the canvas to open the context menu.

```jsx {10-21} showLineNumbers title="App.jsx"
import React from "react";
import { Unity, useUnityContext } from "react-unity-webgl";

function App() {
const { unityProvider } = useUnityContext({
loaderUrl: "build/myunityapp.loader.js",
dataUrl: "build/myunityapp.data",
frameworkUrl: "build/myunityapp.framework.js",
codeUrl: "build/myunityapp.wasm",
});

return (
<Unity
unityProvider={unityProvider}
disabledCanvasEvents={["dragstart", "scroll"]}
/>
);
}
```
4 changes: 4 additions & 0 deletions documentation/sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@
"type": "doc",
"id": "api/webgl-rendering-context"
},
{
"type": "doc",
"id": "api/disabled-canvas-events"
},
{
"type": "doc",
"id": "api/meta-data"
Expand Down

0 comments on commit f693c58

Please sign in to comment.