processing / processing/p5.js

Add an easier way to disable right-click context menus on the canvas

Open
#7,098 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area:DOM Area:Events Feature Request
Dominant language
JavaScript
Stars
24k
Forks
3.8k
Avg merge
3d 16h
Merged PRs (30d)
25

Description

Increasing access

Would allow developers of low technical skill to freely use the right mouse button in their sketches without having to copy/paste cryptic lines from StackOverflow.

Most appropriate sub-area of p5.js?
  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)
Feature request details

When making a sketch that uses mouseButton === RIGHT, students/users are currently surprised that this results in a context menu popping up.
Unfortunately, the simplest way to disable that context menu right now is to add code akin to (c.ref. StackOverflow):

function setup() {
  // createCanvas() ...
  document.querySelector('canvas').addEventListener('contextmenu', e => e.preventDefault())
}

However, that code is a significant step up from a simple if (mouseButton === RIGHT).

Having a simpler API to disable the context menu would be much appreciated. For example, something like:

createCanvas(400, 400, {contextmenu: false})
createCanvas(400, 400, WEBGL, {contextmenu: false})
// or:
createCanvas(400, 400).disableContextMenu()
// or:
createCanvas(400, 400)
disableContextMenu()
// or:
function setup() { ... }
function contextMenu(e) {
  e.preventDefault() // still "ugly", but at least reasonably okay
}
// or:
function setup() { ... }
function contextMenu() {
  return true // somewhat magic
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the createCanvas API and the canvas DOM/event handling related to the contextmenu event. Compare the proposed API forms and existing mouseButton === RIGHT behavior; done means providing a documented, beginner-friendly way to disable the canvas context menu, with coverage for both regular and WEBGL canvas creation if supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
accessibility, frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.