Skip to content
Browse files

Respect explicit active prop on container

  • Loading branch information...
1 parent 39062be commit e4bc0712a1a9cfc45c634eeed0b4d60f2f56c2fa @taion taion committed
Showing with 29 additions and 1 deletion.
  1. +5 −1 src/LinkContainer.js
  2. +24 −0 tests/LinkContainer.spec.js
View
6 src/LinkContainer.js
@@ -32,7 +32,10 @@ export default class LinkContainer extends React.Component {
// Ignore if rendered outside Router context; simplifies unit testing.
if (router) {
props.href = router.createHref(to);
- props.active = router.isActive(to, onlyActiveOnIndex);
+
+ if (props.active == null) {
+ props.active = router.isActive(to, onlyActiveOnIndex);
+ }
}
return React.cloneElement(React.Children.only(children), props);
@@ -46,6 +49,7 @@ LinkContainer.propTypes = {
React.PropTypes.object,
]).isRequired,
onClick: React.PropTypes.func,
+ active: React.PropTypes.bool,
disabled: React.PropTypes.bool.isRequired,
children: React.PropTypes.node.isRequired
};
View
24 tests/LinkContainer.spec.js
@@ -165,6 +165,30 @@ describe('LinkContainer', () => {
it('should not be active when on a different route', () => {
expect(renderComponent('/bar').className).to.not.match(/\bactive\b/);
});
+
+ it('should respect explicit active prop on container', () => {
+ const router = ReactTestUtils.renderIntoDocument(
+ <Router history={createMemoryHistory('/foo')}>
+ <Route
+ path="/"
+ component={() => (
+ <LinkContainer to="/bar" active>
+ <Component>Bar</Component>
+ </LinkContainer>
+ )}
+ >
+ <Route path="foo" />
+ <Route path="bar" />
+ </Route>
+ </Router>
+ );
+
+ const component = ReactTestUtils.findRenderedComponentWithType(
+ router, Component
+ );
+ expect(ReactDOM.findDOMNode(component).className)
+ .to.match(/\bactive\b/);
+ });
});
describe('disabled state', () => {

0 comments on commit e4bc071

Please sign in to comment.
Something went wrong with that request. Please try again.