-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
LinkContainer for using arbitrary components as links #1965
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
This has been discussed previously in #85 (and elsewhere). We're not going to support using arbitrary DOM elements as links because they are inaccessible. You're breaking the web when you do that. |
I'm just as keen on not breaking a11y. The actual component in question looks something like: const MenuItem = ({active, ...props}) => (
<li className={classNames('some-bootstrap-stuff', {active})>
<a {...props} />
</li>
); The intended use is something like <Menu>
<MenuItem href="foo">Foo</MenuItem>
<MenuItem href="bar" active>Bar</MenuItem>
</Menu> With React Router it'd look instead like: <Menu>
<LinkContainer to="/foo">
<MenuItem>Foo</MenuItem>
</LinkContainer>
<LinkContainer to="/bar">
<MenuItem>Bar</MenuItem>
</LinkContainer>
</Menu> As far as I'm aware, this maintains all the relevant a11y considerations, since we're still using The alternative per #85 would be to re-implement every one of these components with a separate React Router-specific implementation that uses |
Per our discussion earlier I concede your point that this makes it too easy to use inaccessible links and would not be a good fit to ship with React Router. I do still need to have this in the React-Bootstrap integration, but that's my problem, not yours. |
@taion I tried React-Router-Bootstrap but I could not get it to work. Probably not the best solution, but I did this to get react-bootstrap to play nice with react-router:
|
Motivating example: React-Bootstrap has a
NavItem
component that's styled as a Bootstrap nav item. I want to be able to use this (and other components like it) as a link to a React Router route. I think the most straightforward way to do this is to have aLinkContainer
component that injectshref
andonClick
to its child. That way I can do e.g.The
LinkContainer
component I'm using right now is:I'm currently shipping this in React-Router-Bootstrap, but it might make sense as part of React Router, though I don't know if the special-casing for the
disabled
prop is something that makes sense outside of the React-Bootstrap context.I already have code and tests for this, so I can PR it if you think it makes sense.
The text was updated successfully, but these errors were encountered: