1.5.0 • Published 3 years ago

primary-click v1.5.0

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

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)}>
1.5.0

3 years ago

1.4.0

4 years ago

1.3.1

5 years ago

1.3.0

6 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago

0.0.2

8 years ago

0.0.1

8 years ago