Tabs: Expose easier way to access current tab id.
See original GitHub issue🚀 Feature request (I think)
Motivation
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.
Example
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) {
setSelectedTab(selectedId)
}
}
...
<Tabs>
<TabList aria-hidden={true} space="medium">
<Tab id="book-now">Now booking</Tab>
<Tab id="coming-soon">Coming soon</Tab>
</TabList>
<TabAwareSlot>{({ selectedId }) => <>{setTabId(selectedId)}</>}</TabAwareSlot>
<TabPanel id="book-now">
<FilmViewer />
</TabPanel>
<TabPanel render="lazy" id="coming-soon">
<ComingSoon />
</TabPanel>
</Tabs>
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:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top 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 >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
@scottlovegrove FYI, you can now use the tabs as a controlled component using the
selectedId
andonSelectedIdChange
props. This was introduced with https://github.com/Doist/reactist/pull/662That works for me 👍🏻