question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

reach/tabs can't be used with react-router

See original GitHub issue

šŸ› Bug report

Current Behavior

To be able to have all the browser native features (open in new tab, copy linkā€¦) I want to use reach/tabs with Link from react-router. So far Iā€™m failing, and I donā€™t really know why šŸ˜•

Expected behavior

I want to have a tab system connected to the router.

Reproducible example

https://codesandbox.io/s/small-cdn-dr1lh?file=/src/App.tsx

Click on one link/tab => image

Suggested solution(s)

Additional context

Iā€™m using react-router:4.3.1, all the details are in the repro example šŸ˜‰

Your environment

Software Name(s) Version
Reach Package tabs 0.10.5
React 16.12.0
Browser chrome latest
Assistive tech
Node
npm/yarn
Operating System

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
fabien0102commented, Mar 31, 2021

@chaance I did play a bit with the repro codesanding, and indeed this is working! Just noticed than when you are playing with the keyboard navigation (left / right to change tab) the url and the focus state are not following.

9766d810-6ee3-46be-9763-a8d1c2939794

2reactions
ghostdcommented, Jul 7, 2020

Hi,

Here what i found after some investigation:

  • we call ownRef.current.focus() without checking if the target is a host element with a focus method (aka HTMLElement)
  • we pass the reference into the ref property but the react-router Link component uses innerRef

How can we improve this part?

  • check if the target element has a focus method?
  • add a property to change the property receiving the reference? (<Tab as={Link} asRef="innerRef" to="/three">)
    • this option will allow the developers to use components using innerRef or other ā€œnot refā€ properties to forward a reference
  • other idea?

In the mean time, (not tested) i guess you can wrap the Link into a CustomLink to forward the ref prop to the react-router innerRef property.

I think i can provide a PR when weā€™ll have chosen an option.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling Tabs Using Page URLs and React Router Doms
Learn how to maintain your active tab by using URL parameters and leveraging React Router Dom instead of using React state.
Read more >
Tabs - Reach UI
Accessible tabs component for React. ... You can render any other elements you want inside of Tabs , but TabList should only render...
Read more >
Should I use react-router for a tabs component? - Stack Overflow
Yes, this is a perfect job for React Router because it focuses on simplifying the URL redirection process for Single Page Apps. The...
Read more >
Announcing Reach UI Tabs - React Training
The latest member of the Reach UI family is here! Tab interfaces are incredibly common on the web, and really easy to build...
Read more >
React & Material UI #19: Tabs + Tabs with React Router
In this video we go over:- The Material UI Tabs and Tab component documentation and props- How the Tab Panel in Material ui...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found