Design Converter
Education
Last updated on Mar 12, 2025
•8 mins read
Last updated on Mar 12, 2025
•8 mins read
Looking for an easy way to organize content in a React app?
React-Bootstrap tabs make it simple to create dynamic tabbed interfaces. They help users switch between sections without losing track of where they are.
The tabs component works with React-Bootstrap’s Nav and TabPane elements, making it easy to manage content. With flexible nav-link and nav-item elements, developers can customize the look and feel while keeping the user experience smooth.
• Easy Navigation: Users can quickly switch between sections.
• Customizable: Can be styled using Bootstrap classes.
• Screen Reader Friendly: Follows the standard WAI ARIA pattern for accessibility.
• Seamless Integration: Works with React Bootstrap's component-based approach.
The tabs component in React Bootstrap is essential for building dynamic tabbed interfaces. It enables seamless switching between different content sections using nav link and nav item elements. The tabs component is designed according to the standard WAI-ARIA pattern, ensuring accessibility for screen readers and keyboard navigation.
• Easy Integration: Works well with other React Bootstrap components.
• Customizable: Supports different layouts and styles.
• Supports Events: The callback fired when switching tabs allows better control.
• Flexible Content Handling: Each tab pane can display unique content, including forms, images, and dynamic data.
Example of a Simple Tabs Component
1import { Tabs, Tab } from 'react-bootstrap'; 2 3function SimpleTabs() { 4 return ( 5 <Tabs defaultActiveKey="home" id="uncontrolled-tab-example"> 6 <Tab eventKey="home" title="Home"> 7 <p>Home tab content.</p> 8 </Tab> 9 <Tab eventKey="profile" title="Profile"> 10 <p>Profile tab content.</p> 11 </Tab> 12 <Tab eventKey="contact" title="Contact"> 13 <p>Contact tab content.</p> 14 </Tab> 15 </Tabs> 16 ); 17} 18 19export default SimpleTabs;
In this uncontrolled tab example, the default value of defaultActiveKey sets the initially selected tab. The tab eventKey helps track which tab pane should be displayed.
The tabs component in React Bootstrap allows extensive customization using TabContainer, TabContent, and TabPane. These elements help in designing more complex layouts while keeping the structure manageable. Developers can use nav link and nav item to create interactive navigation.
• TabContainer: Wraps the entire tabs component to manage active tabs.
• TabContent: Holds the tab pane elements.
• TabPane: Displays content linked to each nav item.
Example of a Custom Tabs Component
This example showcases a custom tabs component where navigation and content are structured separately.
1import { TabContainer, Nav, TabContent, TabPane } from 'react-bootstrap'; 2 3function CustomTabs() { 4 return ( 5 <TabContainer id="custom-tabs-example" defaultActiveKey="first"> 6 <Nav variant="pills"> 7 <Nav.Item> 8 <Nav.Link eventKey="first">First</Nav.Link> 9 </Nav.Item> 10 <Nav.Item> 11 <Nav.Link eventKey="second">Second</Nav.Link> 12 </Nav.Item> 13 <Nav.Item> 14 <Nav.Link eventKey="contact">Contact</Nav.Link> 15 </Nav.Item> 16 </Nav> 17 <TabContent> 18 <TabPane eventKey="first"> 19 <p>First tab content.</p> 20 </TabPane> 21 <TabPane eventKey="second"> 22 <p>Second tab content.</p> 23 </TabPane> 24 <TabPane eventKey="contact"> 25 <p>Contact tab content.</p> 26 </TabPane> 27 </TabContent> 28 </TabContainer> 29 ); 30} 31 32export default CustomTabs;
• eventKey: Assigns a tab eventKey to each tab-pane and its corresponding nav item.
• onSelect Callback Fired: Can handle actions when a new tab is selected.
• Initial Prop: Defines which tab pane should be active by default.
• Nav Variants: Supports tabs, pills, or custom styling.
The bootstrap tabs component in React Bootstrap provides a seamless way to manage dynamic tabbed interfaces. It ensures that users can switch between sections efficiently using tab content, nav item, and tab-pane.
• Default Animation Strategy: Smooth transitions between tabs.
• Active Tab Control: The initial prop determines the currently active tab.
• onSelect Callback Fired: Allows actions when switching tabs.
• Custom Element Type: Developers can use a custom element for more control.
• Mount Tabs Efficiently: Option to enter transition to mount only active content.
Example of Bootstrap Tabs with Custom Properties
1import { Tabs, Tab } from 'react-bootstrap'; 2import { useState } from 'react'; 3 4function CustomBootstrapTabs() { 5 const [key, setKey] = useState('home'); 6 7 return ( 8 <Tabs 9 id="custom-bootstrap-tabs" 10 activeKey={key} 11 onSelect={(k) => setKey(k)} 12 transition={false} // Disables default animation strategy 13 > 14 <Tab eventKey="home" title="Home"> 15 <p>Home tab content.</p> 16 </Tab> 17 <Tab eventKey="profile" title="Profile"> 18 <p>Profile tab content.</p> 19 </Tab> 20 <Tab eventKey="contact" title="Contact"> 21 <p>Contact tab content.</p> 22 </Tab> 23 </Tabs> 24 ); 25} 26 27export default CustomBootstrapTabs;
The TabContainer component in React Bootstrap is a fundamental structure that organizes tab content effectively. It ensures a default animation strategy while allowing developers to mount tabs selectively. The tab eventKey plays a crucial role in linking navigation items with their respective tab pane elements.
• TabContainer: Wraps all tab content and controls the active state.
• TabContent: Holds all tab pane components.
• TabPane: Displays the actual tab content when the corresponding nav link is active.
• GenerateChildId: Creates a unique ID for accessibility and tracking.
Example of Tab Container and Content
1import { TabContainer, Nav, TabContent, TabPane } from 'react-bootstrap'; 2 3function TabContainerExample() { 4 return ( 5 <TabContainer id="tab-container-example" defaultActiveKey="first"> 6 <Nav variant="tabs"> 7 <Nav.Item> 8 <Nav.Link eventKey="first">First Tab</Nav.Link> 9 </Nav.Item> 10 <Nav.Item> 11 <Nav.Link eventKey="second">Second Tab</Nav.Link> 12 </Nav.Item> 13 <Nav.Item> 14 <Nav.Link eventKey="contact">Contact Tab</Nav.Link> 15 </Nav.Item> 16 </Nav> 17 18 <TabContent> 19 <TabPane eventKey="first"> 20 <p>First tab content.</p> 21 </TabPane> 22 <TabPane eventKey="second"> 23 <p>Second tab content.</p> 24 </TabPane> 25 <TabPane eventKey="contact"> 26 <p>Contact tab content.</p> 27 </TabPane> 28 </TabContent> 29 </TabContainer> 30 ); 31} 32 33export default TabContainerExample;
Styling bootstrap tabs in React Bootstrap allows developers to create visually appealing dynamic tabbed interfaces. Different nav link styles, alignments, and layout adjustments can be applied to enhance usability. The nav item elements can be modified using Bootstrap classes to achieve specific styles.
Style | Class Name | Description |
---|---|---|
Standard Tabs | .nav-tabs | Creates a classic tabbed interface. |
Pill Tabs | .nav-pills | Generates rounded, pill-shaped tabs. |
Fill Tabs | .nav-fill | Ensures nav items take up all available width. |
Justified Tabs | .nav-justified | Forces each nav item to have the same width. |
Left Aligned Tabs | .flex-column | Creates a left tabs example with vertical alignment. |
Example of Styled Tabs
1import { Tabs, Tab } from 'react-bootstrap'; 2 3function StyledTabs() { 4 return ( 5 <Tabs defaultActiveKey="home" id="styled-tabs" className="nav-tabs"> 6 <Tab eventKey="home" title="Home"> 7 <p>Home tab content.</p> 8 </Tab> 9 <Tab eventKey="profile" title="Profile"> 10 <p>Profile tab content.</p> 11 </Tab> 12 <Tab eventKey="contact" title="Contact"> 13 <p>Contact tab content.</p> 14 </Tab> 15 </Tabs> 16 ); 17} 18 19export default StyledTabs;
For a left tabs example, the flex-column class is used to arrange nav items vertically.
1import { TabContainer, Nav, TabContent, TabPane } from 'react-bootstrap'; 2 3function LeftAlignedTabs() { 4 return ( 5 <TabContainer id="left-tabs-example" defaultActiveKey="first"> 6 <div className="d-flex"> 7 <Nav variant="pills" className="flex-column"> 8 <Nav.Item> 9 <Nav.Link eventKey="first">First</Nav.Link> 10 </Nav.Item> 11 <Nav.Item> 12 <Nav.Link eventKey="second">Second</Nav.Link> 13 </Nav.Item> 14 </Nav> 15 <TabContent className="p-3"> 16 <TabPane eventKey="first"> 17 <p>First tab content.</p> 18 </TabPane> 19 <TabPane eventKey="second"> 20 <p>Second tab content.</p> 21 </TabPane> 22 </TabContent> 23 </div> 24 </TabContainer> 25 ); 26} 27 28export default LeftAlignedTabs;
• Use .nav-fill or .nav-justified to evenly distribute nav items across the available width.
• Apply flex-column for left tabs example where nav items are vertically aligned.
• Use fill and justify modifiers when spacing needs to be adjusted dynamically.
• Ensure proper spacing using the grid system and horizontal space adjustments.
Applying these styles helps maintain a structured and user-friendly tabs component while ensuring accessibility.
The bootstrap tabs component in React Bootstrap supports built-in JavaScript behaviors that enhance dynamic tabbed interfaces. By utilizing tab-related events, developers can handle state changes efficiently. These events provide better user interaction tracking and debugging options.
The tab eventkey is essential in managing interactions between nav item, nav link, and tab pane elements. The following events help in controlling tab content behavior:
Event Name | Description |
---|---|
show.bs.tab | Fires before a new tab pane is displayed. |
shown.bs.tab | Fires after a tab pane becomes visible. |
hide.bs.tab | Fires before the current active tab is hidden. |
hidden.bs.tab | Fires after the previous active tab is completely hidden. |
Example of Handling Tab Events
1import { Tabs, Tab } from 'react-bootstrap'; 2 3function TabEventsExample() { 4 const handleSelect = (key) => { 5 console.log(`Tab changed to: ${key}`); 6 }; 7 8 return ( 9 <Tabs id="tab-events-example" defaultActiveKey="home" onSelect={handleSelect}> 10 <Tab eventKey="home" title="Home"> 11 <p>Home tab content.</p> 12 </Tab> 13 <Tab eventKey="profile" title="Profile"> 14 <p>Profile tab content.</p> 15 </Tab> 16 <Tab eventKey="contact" title="Contact"> 17 <p>Contact tab content.</p> 18 </Tab> 19 </Tabs> 20 ); 21} 22 23export default TabEventsExample;
• Always use matching eventkey to maintain consistency between nav item and tab pane.
• Ensure dropdown menus are not included in tab content for a better usability perspective.
• Log callback fired events to monitor user interactions effectively.
• Set type argument properly when extending tab behavior with additional functions.
Handling JavaScript events in React Bootstrap Tabs provides flexibility and better control over user interactions.
React-Bootstrap Tabs make it easy to create clean and responsive tabbed interfaces in React. By using components like TabContainer, TabContent, and TabPane, developers can organize content neatly and improve user experience. The built-in event handling and flexible styling options make it simple to adjust the design to match different project needs.
To get the most out of React-Bootstrap Tabs, try different layouts, adjust the styles, and fine-tune the interactions. A little experimentation can go a long way in creating a smooth and engaging user interface.
Tired of manually designing screens, coding on weekends, and technical debt? Let DhiWise handle it for you!
You can build an e-commerce store, healthcare app, portfolio, blogging website, social media or admin panel right away. Use our library of 40+ pre-built free templates to create your first application using DhiWise.