Home

Awesome

React-Tappable

Tappable component for React. Abstracts touch events to implement onTap, onPress, and pinch events.

The events mimic their native equivalents as closely as possible:

When touch events are not supported, it will fall back to mouse events. Keyboard events are also supported, emulating the behaviour of native button controls.

Demo & Examples

Live demo: jedwatson.github.io/react-tappable

To build the examples locally, run:

npm install
gulp dev

Then open localhost:8000 in a browser.

Installation

The easiest way to use React-tappable is to install it from npm.

npm install react-tappable --save

Ensure to include it in your own React build process (using Browserify, etc).

You could also use the standalone build by including dist/react-tappable.js in your page; but, if you do this, make sure you have already included React, and that it is available globally.

Usage

React-tappable generates a React component (defaults to <span>) and binds touch events to it.

To disable default event handling (e.g. scrolling) set the preventDefault prop.

import Tappable from 'react-tappable';

<Tappable onTap={this.handleTapEvent}>Tap me</Tappable>

For a lighter component, you can opt-in to just the features you need:

import Tappable from 'react-tappable/lib/Tappable';
import Pinchable from 'react-tappable/lib/Pinchable';
import TapAndPinchable from 'react-tappable/lib/TapAndPinchable';

<Tappable onTap={this.handleTapEvent}>I respond to Tap events</Tappable>
<Pinchable onPinch={this.handlePinch}>I respond to Pinch events</Pinchable>
<TapAndPinchable onTap={this.handleTapEvent} onPinch={this.handlePinch}>In respond to both!</TapAndPinchable>

The TapAndPinchable component is the default one you get when you just import react-tappable.

Properties

Special Events

These are the special events implemented by Tappable.

Pinch Events

Pinch events come with a special object with additional data to actually be more useful than the native events:

Known Issues

Native Events

The following native event handlers can also be specified.

Returning false from onKeyDown, onMouseDown, or onTouchStart handlers will prevent Tappable from handling the event.

Changelog

See CHANGES.md

License

Copyright (c) 2017 Jed Watson. MIT