The Wayback Machine - https://web.archive.org/web/20201202055831/https://github.com/reactstrap/reactstrap/issues/1552
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mountOnEnter in Tab component #1552

Open
ismaildervisoglu opened this issue Jul 2, 2019 · 5 comments
Open

Support mountOnEnter in Tab component #1552

ismaildervisoglu opened this issue Jul 2, 2019 · 5 comments

Comments

@ismaildervisoglu
Copy link

@ismaildervisoglu ismaildervisoglu commented Jul 2, 2019

  • components: tab
  • reactstrap version: 7.1.0
  • react version 16.8.4

Does TabPane support mountOnEnter props. If not support can you add this feature?

@epeterson320
Copy link

@epeterson320 epeterson320 commented Jul 8, 2019

To add some context: This supports a use case I have where some responsive visualizations use the width of their container to lay out their content. If the tab content mounts before the tab is selected (when it is hidden), the width is calculated to be zero and the visualization doesn't re-render when the tab is focused, so the tab content area appears blank (its child is a component 0px wide).

@melissight
Copy link

@melissight melissight commented Nov 14, 2019

I would love this feature as well. I have API calls that I do not want to run until the new tab is selected.

@TheSharpieOne
Copy link
Member

@TheSharpieOne TheSharpieOne commented Nov 14, 2019

Sure, this can be an optional prop, when mountOnEnter is true it will mount and unmount the component based on the visibility of the tab.

For now the workaround is to control mounting yourself similar to:

import React, { useState } from 'react';
import { TabContent, TabPane, Nav, NavItem, NavLink, Card, Button, CardTitle, CardText, Row, Col } from 'reactstrap';
import classnames from 'classnames';

const Example = (props) => {
  const [activeTab, setActiveTab] = useState('1');

  const toggle = tab => {
    if(activeTab !== tab) setActiveTab(tab);
  }

  return (
    <div>
      <Nav tabs>
        <NavItem>
          <NavLink
            className={classnames({ active: activeTab === '1' })}
            onClick={() => { toggle('1'); }}
          >
            Tab1
          </NavLink>
        </NavItem>
        <NavItem>
          <NavLink
            className={classnames({ active: activeTab === '2' })}
            onClick={() => { toggle('2'); }}
          >
            Moar Tabs
          </NavLink>
        </NavItem>
      </Nav>
      <TabContent activeTab={activeTab}>
        <TabPane tabId="1">
          {activeTab === '1' && <Row>
            <Col sm="12">
              <h4>Tab 1 Contents</h4>
            </Col>
          </Row>}
        </TabPane>
        <TabPane tabId="2">
          {activeTab === '2' && <Row>
            <Col sm="6">
              <Card body>
                <CardTitle>Special Title Treatment</CardTitle>
                <CardText>With supporting text below as a natural lead-in to additional content.</CardText>
                <Button>Go somewhere</Button>
              </Card>
            </Col>
            <Col sm="6">
              <Card body>
                <CardTitle>Special Title Treatment</CardTitle>
                <CardText>With supporting text below as a natural lead-in to additional content.</CardText>
                <Button>Go somewhere</Button>
              </Card>
            </Col>
          </Row>}
        </TabPane>
      </TabContent>
    </div>
  );
}

export default Example;
@jomarquez21
Copy link

@jomarquez21 jomarquez21 commented Jan 10, 2020

I think that your workaround isn't right because this would activate the "componentDidMount" life cycle as long as the activeTab is equal to the index.

@TheSharpieOne
Copy link
Member

@TheSharpieOne TheSharpieOne commented Jan 13, 2020

@jomarquez21 isn't that what this issue is asking for? Have the component mount and thus "activate" the componentDidMount life-cycle when it becomes active (when the activeTab is equal to the index)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.