React Bootstrap Collapse

React Collapse - Bootstrap 4 & Material Design

Note: We are transitioning MDB4 to a legacy version and focusing on developing MDB5. While we'll continue to support for the transition period, we encourage you to migrate to MDB5. We're offering a 50% discount on MDB5 PRO to help with your transition, enabling you to leverage the full potential of the latest version. You can find more information here.
get 50% discount on MDB5 PRO

React Bootstrap collapse is a component which toggles content. Useful for grouping great amount of texts and/or graphics into expanding and collapsing items.

Collapse is used to show and hide content. Buttons or anchors are used as triggers that are mapped to specific elements you toggle. Collapsing an element will animate the height from it’s current value to 0.


Basic example

Click the buttons below to show and hide another element:

You can use a link with the href attribute, or a button.

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
        
            
        import React, { Component } from "react";
        import { MDBBtn, MDBCollapse } from "mdbreact";

        class CollapsePage extends Component {
          state = {
            collapseID: ""
          }

          toggleCollapse = collapseID => () => {
            this.setState(prevState => ({
              collapseID: prevState.collapseID !== collapseID ? collapseID : ""
            }));
          }

          render() {
            return (
              <>
              <MDBBtn
                color="primary"
                href="!#"
                onClick={this.toggleCollapse("basicCollapse")}
                style={{ marginBottom: "1rem" }}
            >
              COLLAPSE LINK
            </MDBBtn>
            <MDBBtn
              color="primary"
              onClick={this.toggleCollapse("basicCollapse")}
              style={{ marginBottom: "1rem" }}
            >
              COLLAPSE BUTTON
            </MDBBtn>
                <MDBCollapse id="basicCollapse" isOpen={this.state.collapseID}>
                  <p>
                    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
                    eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim
                    ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
                    aliquip ex ea commodo consequat. Duis aute irure dolor in
                    reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
                    pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
                    culpa qui officia deserunt mollit anim id est laborum
                  </p>
                </MDBCollapse>
              </>
            );
          }
        }

        export default CollapsePage;
        
        
    

Accordion MDB Pro component

Using the card component, you can extend the default collapse behavior to create an accordion.

Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
        
            
        import React, { Component } from "react";
        import { 
          MDBContainer, 
          MDBCollapse, 
          MDBCard, 
          MDBCardBody, 
          MDBCollapseHeader 
        } from "mdbreact";

        class CollapsePage extends Component {
          state={
            collapseID: "collapse3"
          }

          toggleCollapse = collapseID => () =>
            this.setState(prevState => ({
              collapseID: prevState.collapseID !== collapseID ? collapseID : ""
            }));

          render() {
            const { collapseID } = this.state;

            return (
              <MDBContainer>
                <MDBContainer className="mt-5">
                  <MDBCard className="mt-3">
                    <MDBCollapseHeader onClick={this.toggleCollapse("collapse1")}>
                      Collapsible Group Item #1
                      <i className={ collapseID==="collapse1" ? "fa fa-angle-down rotate-icon" : "fa fa-angle-down" } />
                    </MDBCollapseHeader>
                    <MDBCollapse id="collapse1" isOpen={collapseID}>
                      <MDBCardBody>
                        Pariatur cliche reprehenderit, enim eiusmod high life accusamus
                        terry richardson ad squid. 3 wolf moon officia aute, non
                        cupidatat skateboard dolor brunch. Food truck quinoa nesciunt
                        laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a
                        bird on it squid single-origin coffee nulla assumenda shoreditch
                        et. Nihil anim keffiyeh helvetica, craft beer labore wes
                        anderson cred nesciunt sapiente ea proident. Ad vegan excepteur
                        butcher vice lomo. Leggings occaecat craft beer farm-to-table,
                        raw denim aesthetic synth nesciunt you probably haven&apos;t
                        heard of them accusamus labore sustainable VHS.
                      </MDBCardBody>
                    </MDBCollapse>
                  </MDBCard>

                  <MDBCard>
                    <MDBCollapseHeader onClick={this.toggleCollapse("collapse2")}>
                      Collapsible Group Item #2
                      <i className={ collapseID==="collapse2" ? "fa fa-angle-down rotate-icon" : "fa fa-angle-down" } />
                    </MDBCollapseHeader>
                    <MDBCollapse id="collapse2" isOpen={collapseID}>
                      <MDBCardBody>
                        Anim pariatur cliche reprehenderit, enim eiusmod high life
                        accusamus terry richardson ad squid. 3 wolf moon officia aute,
                        non cupidatat skateboard dolor brunch. Food truck quinoa
                        nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua
                        put a bird on it squid single-origin coffee nulla assumenda
                        shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore
                        wes anderson cred nesciunt sapiente ea proident. Ad vegan
                        excepteur butcher vice lomo. Leggings occaecat craft beer
                        farm-to-table, raw denim aesthetic synth nesciunt you probably
                        haven&apos;t heard of them accusamus labore sustainable VHS.
                      </MDBCardBody>
                    </MDBCollapse>
                  </MDBCard>

                  <MDBCard>
                    <MDBCollapseHeader onClick={this.toggleCollapse("collapse3")}>
                      Collapsible Group Item #3
                      <i className={ collapseID==="collapse3" ? "fa fa-angle-down rotate-icon" : "fa fa-angle-down" } />
                    </MDBCollapseHeader>
                    <MDBCollapse id="collapse3" isOpen={collapseID}>
                      <MDBCardBody>
                        Anim pariatur cliche reprehenderit, enim eiusmod high life
                        accusamus terry richardson ad squid. 3 wolf moon officia aute,
                        non cupidatat skateboard dolor brunch. Food truck quinoa
                        nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua
                        put a bird on it squid single-origin coffee nulla assumenda
                        shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore
                        wes anderson cred nesciunt sapiente ea proident. Ad vegan
                        excepteur butcher vice lomo. Leggings occaecat craft beer
                        farm-to-table, raw denim aesthetic synth nesciunt you probably
                        haven&apos;t heard of them accusamus labore sustainable VHS.
                      </MDBCardBody>
                    </MDBCollapse>
                  </MDBCard>
                </MDBContainer>
              </MDBContainer>
            );
          }
        }

        export default CollapsePage;
        
        
    

React Collapse - API

In this section you will find advanced information about the Collapse component. You will find out which modules are required, what are the possibilities of configuring the component, and what events and methods you can use in working with it.


Collapse import statement

In order to use Collapse component make sure you have imported proper module first.

        
            
        import {  MDBCollapse, MDBCollapseHeader } from "mdbreact";
        
        
    

MDBCollapse

The table below shows the configuration options of the MDBCollapse component.

Name Type Default Description Example
className String Adds custom classes <MDBCollapse className="myClass" ... />
isOpen Boolean Defines is accordion opened or closed <MDBCollapse isOpen={true} ... />
delay Object Defines how many milliseconds the open/close event are delayed <MDBCollapse delay={{show: 2000, hide: 4000}} ... />
onOpened function Defines the function which fires when Accordion has opened <MDBCollapse onOpened={() => console.log('hello')} ... />
onClosed function Defines the function which fires when Accordion has closed <MDBCollapse onClosed={() => console.log('hello')} ... />

MDBCollapseHeader

The table below shows the configuration options of the MDBCollapseHeader component.

Name Type Default Description Example
tag String Specifies the custom tag for the MDBCollapseHeader component <MDBCollapseHeader tag="div" ... />
className String Adds custom classes <MDBCollapseHeader className="myClass" ... />