Skip to content

Restrict input

Overview

ReactSketchCanvas allows you to restrict the input to a specific device. This is useful when you want to collect data from a specific device or prevent users from accidentally touching to draw while using a pen.

These are the available options:

  • all (default) - All input devices are allowed.
  • pen - Only pen input is allowed. This includes stylus, Apple Pencil, Wacom, Windows surface pen and other pen devices.
  • mouse - Only mouse input is allowed.
  • touch - Only touch input is allowed. This includes finger touch and other touch devices.

Default behavior

import { ReactSketchCanvas } from "react-sketch-canvas";

export default function App() {
  return (
    <div>
      <h1>Canvas</h1>
      <ReactSketchCanvas allowOnlyPointerType="all" />
    </div>
  );
}

Only allow pen input

import { ReactSketchCanvas } from "react-sketch-canvas";

export default function App() {
  return (
    <div>
      <h1>Canvas</h1>
      <ReactSketchCanvas allowOnlyPointerType="pen" />
    </div>
  );
}

Only allow mouse input

import { ReactSketchCanvas } from "react-sketch-canvas";

export default function App() {
  return (
    <div>
      <h1>Canvas</h1>
      <ReactSketchCanvas allowOnlyPointerType="mouse" />
    </div>
  );
}

Only allow touch input

import { ReactSketchCanvas } from "react-sketch-canvas";

export default function App() {
  return (
    <div>
      <h1>Canvas</h1>
      <ReactSketchCanvas allowOnlyPointerType="touch" />
    </div>
  );
}