primary-click

1.5.0 • Public • Published

primary-click

Detects if the primary button has been clicked in mouse events.

Usage

isPrimaryClick(e {MouseEvent})

Detects if the primary button has been pressed in mouse events.

e is a MouseEvent or Event-like instance (i.e. SyntheticEvent).

Returns a boolean, true if the primary mouse button has been pressed, and no keyboard modifier keys have been pressed.

Example

import { isPrimaryClick } from "primary-click";
 
someDomEl.addEventListener("click", e => {
  if (isPrimaryClick(e)) {
    …
  }
});

onPrimaryClick(func {Function})

Decorates a function so it calls if the primary button has been pressed in mouse events.

fn is the Function to be decorated.

Returns a new function which expects a Event-like instance as the first argument.

Examples

Basic:

import { onPrimaryClick } from "primary-click";
 
someEl.addEventListener("click", onPrimaryClick(e => {
  …
}));

Composed:

import { onPrimaryClick } from "primary-click";
import preventDefault from "prevent-default";
 
someEl.addEventListener("click", onPrimaryClick(preventDefault(e => {
  …
})));

JSX:

<button onClick={onPrimaryClick(myClickHandler)}>

Readme

Keywords

Package Sidebar

Install

npm i primary-click

Weekly Downloads

9

Version

1.5.0

License

MIT

Unpacked Size

10.2 kB

Total Files

8

Last publish

Collaborators

  • jacobbuck