Permalink
Browse files
Respect explicit active prop on container
- Loading branch information...
Showing
with
29 additions
and
1 deletion.
-
+5
−1
src/LinkContainer.js
-
+24
−0
tests/LinkContainer.spec.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
|
|
|
};
|
|
|
|
@@ -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