`Tabs`: Implement developer-friendly api
See original GitHub issueAfter some discussion in our core team meeting yesterday, we decided we’d like to change the Tabs
component api.
Problems
- painful to coordinate indexes between
Tab
+TabPanel
combinations when tabs are dynamic - can’t customize component tree because props are passed directly rather than shared via context (see #3045)
Solution
We’d like to restructure the implementation and api of the Tabs
component to resolve those problems.
Tabs
is indexed bystring
idsTab
relates toTabPanel
viapanelId
propTabPanel
relates toTabs
viaid
prop
Tabs
data is shared via descendant context instead of passed props
const App = () => {
return (
<Tabs defaultTab="a">
<TabList>
{/* can be nested! */}
<div>
<Tab panelId="a">A</Tab>
</div>
<Tab panelId="b">B</Tab>
<Tab panelId="c">C</Tab>
</TabList>
<TabPanels>
{/* can be nested! */}
<div>
<TabPanel id="a">A panel!</TabPanel>
</div>
<TabPanel id="b">B panel!</TabPanel>
<TabPanel id="c">C panel!</TabPanel>
</TabPanels>
</Tabs>
)
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:8
- Comments:7 (2 by maintainers)
Top Results From Across the Web
5 Tips to Build Developer-Friendly API Products
This article elaborates on his ideas regarding the deliberate, rigorous process of building APIs with an intentional design for long-term use.
Read more >API Integrations - Tabs and Spaces
Our API development and integration services enable websites, web applications and mobile apps to seamlessly mobilise your data across complex systems, ...
Read more >Working with the Tabs API - Mozilla - MDN Web Docs
Tabs let a user open several web pages in their browser window and then switch between those web pages. With the Tabs API,...
Read more >Azure API Management : New/Custom Tab in Developer Portal
Use case: The default developer portal of API Management service gives you five tabs (Home, Products, APIs, Application and Issues). But it has ......
Read more >Developer Api - Ultimate Guitar
joncardasis I think the main things would be to be able to provide basic credentials, access my tabs and playlists. It would also...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@with-heart glad that you bring it up.
I also want to ask if it’s possible to bring the original “wrong” implementation of
onChange
back as a option.onChange
only fires when index changes. I tired to useonClick
to replaceonChange
due to some functionalities, butonClick
does not contain the index by default, and I found it’s hard to get the current active index viadoucment.getElementby...()
, Also, the fundamental part:onChange
listen totabIndex
butonClick
is limited by clicking behavior.or make
function onChange(index, default=true) // when set to false means it will be fired even click the same tab
So it allows user to retrig some custom functions even when click the same tabs. It can be extremely handy when there are multiple tabs with it’s own dynamic content, and you only want to refetch data when click the same tabs again as a shortcut behavior.
This would be a huge help, dynamic tabs are a mess especially when trying to map to routes. That is:
defaultIndex
on mount based on the requested route.A new
defaultPanel
prop would take care of (1).Updating the signature of
onChange
to be(index: number, panelId: string | undefined) => void
would take care of (2) and remain backwards compatible.