Tab API Issues #1244
-
Code sandbox illustrating both routing techniques Reference picture for the design we're implementing. So we were working with tabs and a requirement for our product had tabs activate routes which seems like a pretty common pattern for a lot of applications. Part of the reason for our design is that it shows the user that we have a persistent search experience across the tabs (ie. date, subuser, and eventually MSP, and comparison date will be searchable and persistent across views.) To achieve this UX we used the paste tabs and ran into some difficulties. useTabState ImplementationConsWhen using useTabState we have to partially re-implement a routing solution. You can see the 3 useEffects to accomplish this.
The routing behavior is very custom logic and implementation was not straightforward it took me 2~ hours to implement this and get it working compared to the routing method which took around 30min and to me is a "more correct" solution when it comes to navigation (middle click works, can right click tabs etc.) ProsI really don't like this implementation so I'm having a hard time filling this one out. I guess the nice thing is that since it's essentially off the shelf Reakit we don't have to do too much to get some accessibility and functionality by wrapping the implementation. Router ImplementationMost of the issues with this approach are related to resolving some compatibility issues between the tabs and the link. Cons
Screen.Recording.2021-03-03.at.2.29.27.PM.movProsThis is my preferred approach it was easier to implement and get correct while using composable components instead of custom logic. Other than compatibility issues I was able to achieve desired behavior without writing a custom effects/state handling/etc. and I was able to do it quickly. History and navigation worked correctly basically automagically. Potential SolutionsAt the end of the day we really just need the presentational components to be exposed so we can extend our own tab based functionality. If we had presentational components we could trivially wrap them in routers/links and create our interface in a composable manner without custom logic. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
+1 on this - I agree with Alex that a great solution would be to provide a presentational version of the tab components that does not try to take over state management. We found this pattern generally to work quite well for us @ SendGrid with our ui-components repo. I see there is a |
Beta Was this translation helpful? Give feedback.
-
Hi all, This is a really good question. I forked the Codesandbox and added a third option: https://codesandbox.io/s/zomg-tabs-forked-wjyid?file=/src/TabsWithProgrammaticRouter.tsx Currently there's a warning about Let me know if my third option works for you all! |
Beta Was this translation helpful? Give feedback.
Hi all,
This is a really good question. I forked the Codesandbox and added a third option: https://codesandbox.io/s/zomg-tabs-forked-wjyid?file=/src/TabsWithProgrammaticRouter.tsx
Currently there's a warning about
onClick
prop onTab
components, which is an oversight also reported here: #1250. We plan to fix this soon.Let me know if my third option works for you all!