-
|
Does Tabs has any event available? So I can trigger other functions when specific tab shown or hidden. Like how I did with Bootstrap: tabEl.addEventListener('shown.bs.tab', function (event) {
event.target // newly activated tab
event.relatedTarget // previous active tab
}) |
Beta Was this translation helpful? Give feedback.
Answered by
Josh-Cena
Sep 12, 2021
Replies: 2 comments 2 replies
-
|
No, tabs don't emit custom events, so if you want to change its behavior, you need to swizzle |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
The React way is actually to pass the behavior into // Tabs.js
function Tabs(props) {
const handleTabChange = (event) => {
// ...
props.onTabChange();
}
// ...
}
// your-page.{md,js}
<Tabs onTabChange={() => console.log("Tabs changed")} />
// ...If you absolutely need to emit events, do it in the old way with DOM: function Tabs(props) {
const ref = React.createRef();
const handleTabChange = (event) => {
// ...
ref.current?.dispatchEvent(new Event('tabChange'));
}
return (
<div ref={ref}>
{/* the component */}
</div>
)
}(Hope the latter works, correct me if it doesn't) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
gouku
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The React way is actually to pass the behavior into
Tabsas a callback:If you absolutely need to emit events, do it in the old way with DOM:
(Hope the latter works, correct me if it doesn't)