Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 90ee028

Browse files
committed
Merge pull request #36 from merk/patch-1
Handle disabled components
2 parents 093506b + cce3f67 commit 90ee028

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

‎src/LinkMixin.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function isModifiedEvent(event) {
1212
module.exports = {
1313
propTypes: {
1414
activeClassName: React.PropTypes.string.isRequired,
15+
disabled: React.PropTypes.bool,
1516
to: React.PropTypes.string.isRequired,
1617
params: React.PropTypes.object,
1718
query: React.PropTypes.object,
@@ -56,6 +57,10 @@ module.exports = {
5657
handleRouteTo: function (event) {
5758
var allowTransition = true;
5859
var clickResult;
60+
61+
if (this.props.disabled) {
62+
return;
63+
}
5964

6065
if (this.props.onClick) {
6166
clickResult = this.props.onClick(event);

‎tests/NavItemLink.spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,32 @@ describe('A NavItemLink', function () {
124124
});
125125
});
126126

127+
it('when disabled does not proceed', function () {
128+
var NavItemLinkHandler = React.createClass({
129+
handleClick: function (event) {
130+
throw new Error('click should not be called');
131+
},
132+
133+
render: function () {
134+
return <NavItemLink to="foo" disabled onClick={this.handleClick}>NavItemLink</NavItemLink>;
135+
}
136+
});
137+
138+
var routes = [
139+
<Route name="foo" handler={Foo} />,
140+
<Route name="link" handler={NavItemLinkHandler} />
141+
];
142+
var div = document.createElement('div');
143+
var testLocation = new TestLocation();
144+
testLocation.history = ['/link'];
145+
146+
Router.run(routes, testLocation, function (Handler) {
147+
React.render(<Handler/>, div, function () {
148+
click(div.querySelector('a'));
149+
});
150+
});
151+
});
152+
127153
it('transitions to the correct route', function (done) {
128154
var div = document.createElement('div');
129155
var testLocation = new TestLocation();

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /