-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Links as Bootstrap Tabs #666
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
Comments
Hm. Can you subclass stuff in react? This would be pretty easy if I could just make my own version of Link with a slightly different render method on it. |
React doesn't allow inheritance (at least not until ES6) and it's a deliberate decision:
Mostly when you want to inherit something in UI, you can achieve the same much easier with composition. For example: var MyLink = React.createClass({
mixins: [State],
render: function () {
var isActive = this.isActive(this.props.to, this.props.params, this.props.query);
return (
<li className={isActive ? 'active' : null}>
<Link {...this.props}>{this.props.children}</Link>
</li>
);
}
});
|
This works, thanks. |
@gaearon Just updated to latest and I get this deprecation message:
The new code can be found here: https://github.com/rackt/react-router/blob/master/docs/api/RouterContext.md var Tab = React.createClass({
render: function () {
var { router } = this.context;
var isActive = router.isActive(this.props.to, this.props.params, this.props.query);
var className = isActive ? 'active' : '';
var link = (
<Link {...this.props} />
);
return <li className={className}>{link}</li>;
}
}); HOWEVERThis is working with the latest version of React apparently (0.13.1). |
The docs fail to mention you need to declare |
@ryanflorence I added c17ef27 as this seems to be the main source of confusion. |
Thanks @gaearon and @justin808 Using the docs as referenced by @gaearon here: https://github.com/rackt/react-router/blob/c17ef2717bef98c145f90e9a46c13f9e211bf1ed/docs/api/RouterContext.md Here is my final component that is working as of React v0.13.1 and React-Router v0.13.2 var React = require('react'),
Link = require('react-router').Link;
var NavTab = React.createClass({
contextTypes: {
router: router: React.PropTypes.func
},
render: function () {
var isActive = this.context.router.isActive(this.props.to, this.props.params, this.props.query);
var className = isActive ? 'active' : '';
var link = (
<Link {...this.props} />
);
return <li className={className}>{link}</li>;
}
});
module.exports = NavTab; |
isActive is not undefined |
You can "route around" that issue also by just fixing bootstrap:
|
In bootstrap, the class="active" on tabs is unfortunately applied to the
<li>
, not the<a>
. Is there a way to work around this, so I can have links that look like bootstrap tabs?The text was updated successfully, but these errors were encountered: