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.

`Tabs`: Implement developer-friendly api

See original GitHub issue

After 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 by string ids
    • Tab relates to TabPanel via panelId prop
    • TabPanel relates to Tabs via id 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:closed
  • Created 2 years ago
  • Reactions:8
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
aboveyunhaicommented, May 21, 2021

@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 use onClick to replace onChange due to some functionalities, but onClick does not contain the index by default, and I found it’s hard to get the current active index via doucment.getElementby...(), Also, the fundamental part: onChange listen to tabIndex but onClick is limited by clicking behavior.

onTabChange( (index) => {
  if(index === tabIndex) return;
})
//this is equivalent to current onChange();

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.

1reaction
kodellcommented, Jun 2, 2021

This would be a huge help, dynamic tabs are a mess especially when trying to map to routes. That is:

  1. I want to set defaultIndex on mount based on the requested route.
  2. I want my URL route to update when I switch tabs.

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.

Read more comments on GitHub >

github_iconTop 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 >

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