preact-long-press-event
v1.0.1
Published
onLongPress event for preact
Downloads
4
Maintainers
Readme
preact-long-press-event: onLongPress
for Preact
onLongPress
is a CustomEvent generated using native Event.
Inspired by long-press
Usage
npm i -S preact-long-press-event
// in your index.js
import injectLongPressEvent from 'preact-long-press-event';
/**
* @params {object} options
*
* Options can be an object containing duration property
*
* {
* duration: <duration_in_milliseconds>
* }
*
* The default delay duration is 1500
*/
injectLongPressEvent();
// in your component
class MyComponent extends Component {
longPress(event) {
// longPress event handller
}
render() {
return (
<div class="app">
<button onLongPress={this.longPress}>Long Press Me!</button>
</div>
);
}
}
Options
duration
a delay duration for long press in milliseconds default is1500
Example
// Set the long press duration to 2 seconds
injectLongPressEvent({
duration: 2000
});