primary-click
v2.0.0
Published
Detects if the primary button has been clicked in mouse events.
Readme
primary-click
Detects if the primary button has been clicked in mouse events.
Usage
isPrimaryClick
Detects if the primary button has been pressed in mouse events.
isPrimaryClick(event {MouseEvent})Parameters
eventis aMouseEvent-like instance.
Return value
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', (event) => {
if (isPrimaryClick(event)) {
…
}
});onPrimaryClick
Decorates a function so it calls if the primary button has been pressed in mouse events.
onPrimaryClick(func {Function})Parameters
funcis theFunctionto be decorated.
Return value
A new function which expects a Event-like instance as the first argument.
Examples
Basic:
import { onPrimaryClick } from 'primary-click';
someEl.addEventListener('click', onPrimaryClick((event) => {
…
}));Composed:
import { onPrimaryClick } from 'primary-click';
import preventDefault from 'prevent-default';
someEl.addEventListener('click', onPrimaryClick(preventDefault((event) => {
…
})));JSX:
<button onClick={onPrimaryClick(myClickHandler)}>