I am trying to add custom styling to the active tab but don't know how to switch the styling class for the active tab.
Following is my code:
import React, { useState } from "react";
import "./styles.css";
import { Container, Row, Col, Tab, Nav } from "react-bootstrap";
export default function App() {
const [key, setKey] = useState("first");
const ActiveStyle = {
textAlign: "center",
background: "white",
borderRadius: "2em",
padding: " 0.3em 1.5em",
letterSpacing: "0.2em"
};
const inActiveStyle = {
...ActiveStyle,
background: "transparent",
"border-color": "transparent",
color: "inherit"
};
return (
<div className="App">
<Container style={{ width: "auto" }}>
<Tab.Container activeKey={key} onSelect={key => setKey(key)}>
<Row style={{ padding: "1em 1em", background: "#EEEEEE" }}>
<Col>
<Nav.Link
eventKey="first"
style={key === "first" ? ActiveStyle : inActiveStyle}
>
<span style={{ fontSize: "larger" }}>Q&A </span>
</Nav.Link>
</Col>
<Col>
<Nav.Link
eventKey="second"
style={key === "second" ? ActiveStyle : inActiveStyle}
>
<span>Exams</span>
</Nav.Link>
</Col>
</Row>
<Tab.Content>
<Tab.Pane eventKey="first">
<Row style={{ height: "90vh" }}>
<p>TAB 1</p>
</Row>
</Tab.Pane>
<Tab.Pane eventKey="second">
<Row style={{ height: "90vh" }}>
<p>TAB 2</p>
</Row>
</Tab.Pane>
</Tab.Content>
</Tab.Container>
</Container>
</div>
);
}
And sandbox link: https://codesandbox.io/s/stupefied-galois-f46s3
codesandboxlink and see everything is ok because you changed the link based on the answer and if the other user have the same issue, they cannot understand this current post. I leave a downvote if you fix your question post I will change it to upvote. 🌹