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: Expose easier way to access current tab id.

See original GitHub issue

🚀 Feature request (I think)


Using the new tabs components, I still found myself needing to know what the currently selected tab id was. I know under the hood these components are using the Reakit tabs, and that does offer access to that via the useTabState hook, but this isn’t available (I don’t think) when using the Reactist tabs.


What I’ve ended up having to do is work around it like this

const [selectedTab, setSelectedTab] = useState<string>('book-now')

function setTabId(selectedId?: string | null) {
    if (selectedId) {
    <TabList aria-hidden={true} space="medium">
        <Tab id="book-now">Now booking</Tab>
        <Tab id="coming-soon">Coming soon</Tab>
    <TabAwareSlot>{({ selectedId }) => <>{setTabId(selectedId)}</>}</TabAwareSlot>
    <TabPanel id="book-now">
        <FilmViewer />

    <TabPanel render="lazy" id="coming-soon">
        <ComingSoon />

Having the TabAwareSlot is fine for if you’re wanting to display something in the UI, but it’s not ideal if you just need the tab id.

Possible implementations

I think maybe exposing the useTabState() hook could help remedy this, or a Reactist variant of this hook.

Issue Analytics

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

github_iconTop GitHub Comments

frankieyancommented, Jul 21, 2022

@scottlovegrove FYI, you can now use the tabs as a controlled component using the selectedId and onSelectedIdChange props. This was introduced with

scottlovegrovecommented, Nov 15, 2021

So yes, we could/should explore a way to make the Tabs component be controlled (). That is, to allow the consumer of that component to own the selected tab state management.

That works for me 👍🏻

Read more comments on GitHub >

github_iconTop Results From Across the Web

chrome.tabs - Chrome Developers
Use the chrome.tabs API to interact with the browser's tab system. You can use this API to create, modify, and rearrange tabs in...
Read more >
Get tab id of tab where script is executing in chrome extensions
An obvious solution is first to get the active tab, and then schedule the timeout, but still there are cases where you might...
Read more >
Current tab id - Google Groups
Is there a way to get the id of the current tab a script is running in? chrome.tabs.getSelected returns the selected tab, but...
Read more >
Working with the Tabs API - Mozilla - MDN Web Docs
Where you want information about the current tab only, you can get a tabs.Tab object for that tab using tabs.getCurrent() . If you...
Read more >
Access label of currently active tab? - Skuid Community
Is there a way that I can access the label of the current tab and render it in a template? jQuery, perhaps?
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 Post

No results found

github_iconTop Related Hashnode Post

No results found