Skip to content

[added] Fast touch clicks #495

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion modules/components/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ var Link = React.createClass({
var props = assign({}, this.props, {
href: this.getHref(),
className: this.getClassName(),
onClick: this.handleClick
onClick: this.handleClick,
onTouchEnd: this.handleClick
});

return React.DOM.a(props, this.props.children);
Expand Down
68 changes: 67 additions & 1 deletion modules/components/__tests__/Link-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var Route = require('../Route');
var Link = require('../Link');
var TestLocation = require('../../locations/TestLocation');
var { Foo } = require('../../__tests__/TestHandlers');
var { click } = React.addons.TestUtils.Simulate;
var { click, touchEnd } = React.addons.TestUtils.Simulate;

describe('A Link', function () {
describe('with params and a query', function () {
Expand Down Expand Up @@ -126,4 +126,70 @@ describe('A Link', function () {

});

describe('when touched', function () {
it('calls a user defined click handler', function (done) {
var LinkHandler = React.createClass({
handleClick: function (event) {
assert.ok(true);
done();
},

render: function () {
return <Link to="foo" onClick={this.handleClick}>Link</Link>;
}
});

var routes = [
<Route name="foo" handler={Foo} />,
<Route name="link" handler={LinkHandler} />
];
var div = document.createElement('div');
TestLocation.history = ['/link'];

Router.run(routes, TestLocation, function (Handler) {
React.render(<Handler/>, div, function () {
touchEnd(div.querySelector('a'));
});
});
});

it('transitions to the correct route', function (done) {
var div = document.createElement('div');
TestLocation.history = ['/link'];

var LinkHandler = React.createClass({
handleClick: function () {
// just here to make sure click handlers don't prevent it from happening
},

render: function () {
return <Link to="foo" onClick={this.handleClick}>Link</Link>;
}
});

var routes = [
<Route name="foo" handler={Foo} />,
<Route name="link" handler={LinkHandler} />
];

var steps = [];

steps.push(function () {
touchEnd(div.querySelector('a'), {button: 0});
});

steps.push(function () {
expect(div.innerHTML).toMatch(/Foo/);
done();
});

Router.run(routes, TestLocation, function (Handler) {
React.render(<Handler/>, div, function () {
steps.shift()();
});
});
});

});

});