How to customize selected Tab styles in React
4 Sep 20268 minutes to read
You can customize the React Tab style by overriding its header and active React Tab CSS classes (for example, .e-tab-header .e-toolbar-item.e-active). Define HTML string for adding animation and customizing the React Tab header and pass it to the text property. Now you can override the style using custom CSS classes added to the React Tab elements.
To place the overrides, add them to the src/index.css file imported by your Vite application (after the Syncfusion theme import). Add the custom class to the React Tab component using the cssClass property to apply the new style, as shown in the sample below.
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { TabComponent, TabItemDirective, TabItemsDirective } from '@syncfusion/ej2-react-navigations';
const App = () => {
let headertext = [
{ 'text': '<div><div class="e-image e-andrew"></div><div class="e-title fade-in">Andrew</div></div>' },
{ 'text': '<div><div class="e-image e-margaret"></div><div class="e-title fade-in">Margaret</div></div>' },
{ 'text': '<div><div class="e-image e-janet"></div><div class="e-title fade-in">Janet</div></div>' }
];
return (<TabComponent heightAdjustMode='Auto' id='tabelement'>
<TabItemsDirective>
<TabItemDirective header={headertext[0]} content={'Andrew received his BTS commercial in 1974 and a Ph.D. in international marketing from the University of Dallas in 1981.He is fluent in French and Italian and reads German.He joined the company as a sales representative, was promoted to sales manager in January 1992 and to vice president of sales in March 1993.Andrew is a member of the Sales Management Roundtable, the Seattle Chamber of Commerce, and the Pacific Rim Importers Association.'}/>
<TabItemDirective header={headertext[1]} content={'Margaret holds a BA in English literature from Concordia College (1958) and an MA from the American Institute of Culinary Arts (1966).She was assigned to the London office temporarily from July through November 1992.'}/>
<TabItemDirective header={headertext[2]} content={'Janet has a BS degree in chemistry from Boston College (1984).She has also completed a certificate program in food retailing management.Janet was hired as a sales associate in 1991 and promoted to sales representative in February 1992.'}/>
</TabItemsDirective>
</TabComponent>);
}
const root = ReactDOM.createRoot(document.getElementById('element'));
root.render(<App />);import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { TabComponent, TabItemDirective, TabItemsDirective } from '@syncfusion/ej2-react-navigations';
const App = () => {
let headertext: any = [
{ 'text': '<div><div id="template-wrap" class="e-image e-andrew"></div><div class="e-title fade-in">Andrew</div></div>' },
{ 'text': '<div><div id="template-wrap" class="e-image e-margaret"></div><div class="e-title fade-in">Margaret</div></div>' },
{ 'text': '<div><div id="template-wrap" class="e-image e-janet"></div><div class="e-title fade-in">Janet</div></div>' }
];
return (
<TabComponent heightAdjustMode='Auto' id='tabelement'>
<TabItemsDirective>
<TabItemDirective header={headertext[0]}
content={'Andrew received his BTS commercial in 1974 and a Ph.D. in international marketing from the University of Dallas in 1981.He is fluent in French and Italian and reads German.He joined the company as a sales representative, was promoted to sales manager in January 1992 and to vice president of sales in March 1993.Andrew is a member of the Sales Management Roundtable, the Seattle Chamber of Commerce, and the Pacific Rim Importers Association.'} />
<TabItemDirective header={headertext[1]}
content={'Margaret holds a BA in English literature from Concordia College (1958) and an MA from the American Institute of Culinary Arts (1966).She was assigned to the London office temporarily from July through November 1992.'} />
<TabItemDirective header={headertext[2]}
content={'Janet has a BS degree in chemistry from Boston College (1984).She has also completed a certificate program in food retailing management.Janet was hired as a sales associate in 1991 and promoted to sales representative in February 1992.'} />
</TabItemsDirective>
</TabComponent>
);
}
const root = ReactDOM.createRoot(document.getElementById('element'));
root.render(<App />);#loader {
color: #008cff;
height: 40px;
left: 45%;
position: absolute;
top: 45%;
width: 30%;
}
#template-wrap {
display: flex;
}
.e-content .e-item {
font-size: 12px;
margin: 10px;
text-align: justify;
}
.container {
min-width: 350px;
max-width: 500px;
margin: 0 auto;
}
.e-image {
background-size: 33px;
width: 33px;
height: 33px;
margin: 0 auto;
}
.e-image.e-andrew { /* csslint allow: adjoining-classes */
background-image: url('https://ej2.syncfusion.com/demos/src/images/employees/3.png');
}
.e-image.e-margaret { /* csslint allow: adjoining-classes */
background-image: url('https://ej2.syncfusion.com/demos/src/images/employees/6.png');
}
.e-image.e-janet { /* csslint allow: adjoining-classes */
background-image: url('https://ej2.syncfusion.com/demos/src/images/employees/7.png');
}
.e-tab .e-toolbar-item .e-title {
margin-top: 8px;
}
.e-toolbar .e-toolbar-items .e-toolbar-item:not(.e-separator),
.e-toolbar .e-toolbar-items .e-toolbar-item .e-tab-wrap {
width: 125px;
height: 50px;
}
.e-tab .e-tab-header .e-toolbar-item.e-active .e-tab-wrap { /* csslint allow: adjoining-classes */
background-color: #08c;
}
.e-tab .e-tab-header {
background-color: #e6e6e6;
}
.e-tab .e-tab-header .e-toolbar-item:not(.e-active) .e-tab-wrap:hover {
background-color: #f2f2f2;
color: #000;
}
.e-tab .e-toolbar .e-toolbar-items .e-toolbar-item .e-text-wrap {
height: 50px;
}
.e-tab .e-toolbar-item.e-active .e-title { /* csslint allow: adjoining-classes */
display: block;
color: white;
}
.e-tab .e-toolbar-item .e-text-wrap,
.e-tab .e-toolbar-item .e-tab-text {
width: inherit;
text-align: center;
}
.e-tab .e-toolbar-item.e-active .e-title.fade-in {
opacity: 1;
animation-name: fadeInOpacity;
animation-iteration-count: 1;
animation-timing-function: ease-in;
animation-duration: 0.5s;
}
@keyframes fadeInOpacity {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}