Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

Commit

Permalink
Merge fd8e03e into 687b169
Browse files Browse the repository at this point in the history
  • Loading branch information
ebednarz committed Jul 23, 2015
2 parents 687b169 + fd8e03e commit 08c54b9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
11 changes: 11 additions & 0 deletions lib/NavLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var NavLink = React.createClass({
executeAction: React.PropTypes.func
},
propTypes: {
activeElement: React.PropTypes.string,
currentRoute: React.PropTypes.object,
currentNavigate: React.PropTypes.object,
href: React.PropTypes.string,
Expand Down Expand Up @@ -116,6 +117,16 @@ var NavLink = React.createClass({
className = className ? (className + ' ') : '';
className += this.props.activeClass || 'active';
style = objectAssign({}, style, this.props.activeStyle);
if (this.props.activeElement) {
return React.createElement(
this.props.activeElement,
objectAssign({}, this.props, {
className: className,
style: style
}),
this.props.children
);
}
}

return React.createElement(
Expand Down
11 changes: 10 additions & 1 deletion tests/unit/lib/NavLink-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('NavLink', function () {
);
}).to.throw();
});
it('should set active state if href matches current route', function () {
it('should set active state by class name if href matches current route', function () {
var navParams = {a: 1, b: 2};
var link = ReactTestUtils.renderIntoDocument(
<MockAppComponent context={mockContext}>
Expand All @@ -101,6 +101,15 @@ describe('NavLink', function () {
);
expect(link.getDOMNode().getAttribute('class')).to.equal('active');
});
it('should set active state by tag name if the optional activeElement property is set', function () {
var navParams = {a: 1, b: 2};
var link = ReactTestUtils.renderIntoDocument(
<MockAppComponent context={mockContext}>
<NavLink activeElement="span" routeName='foo' />
</MockAppComponent>
);
expect(link.getDOMNode().nodeName.toLowerCase()).to.equal('span');
});
it('should set active state with custom class and style', function () {
var link = ReactTestUtils.renderIntoDocument(
<MockAppComponent context={mockContext}>
Expand Down

0 comments on commit 08c54b9

Please sign in to comment.