Due to docs React-Bootstrap supports onSelect method for tabs which fires once tab switch to another tab.
I looking for something similar to native Twitter Bootstrap event hide.bs.tab to determine moment when tab starts closing.
I found some utilities with onExit method, but that doesn’t work for tabs, as for me.
How to do that?
2
Answers
Actually,
onSelect
fires (if you provided it as a prop) as soon as another tab is selected, not after it is switched to. It is then that handler’s job to switch the active tab (or not), perhaps after loading additional information through the wire, and so on.An excerpt from the React-Bootstrap code:
(taken from https://github.com/react-bootstrap/react-bootstrap/blob/44182b72da816b719029355478ef2e7efef522f6/src/Tabs.js#L324)
Then followed by the built-in tab switching but only if you hadn’t provided
onSelect
.For example, your custom
onSelect
handler could display a spinner, fetch data that goes in the new tab, and once that’s done hide the spinner and switch the active tab to that one, using theactiveKey
prop.You can attach an onClick event to the anchor element of your nav-tabs: