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

tab resets to first tab onclick event #63

Closed
aaronucsd opened this issue Jan 14, 2016 · 5 comments
Closed

tab resets to first tab onclick event #63

aaronucsd opened this issue Jan 14, 2016 · 5 comments
Labels

Comments

@aaronucsd
Copy link

Hi. I have an onclick event fire from one of my tabs, but on fire, it somehow reset the tab index to go back to the first tab. Say i have 2 tabs, and i'm on the second page of the tab 2, which has Griddle table, when i click on something in one of the griddle's table column ( i have an onclick on an item there ) it triggers the react tab to go back to the first tab vs staying put. I need it to stay put on tab 2 vs somehow route back to tab 1. Any ideas?

const LinkComponent = ({ data, rowData }) => {
  let result = <span></span>;
  if (data) {
    result = (
      <div>
        <span>{rowData.user}</span>&nbsp;
        <span onClick={this.props.onClickUserDetails.bind(this, rowData.user)}>
          <i className='fa fa-info-circle fa-lg'></i>
        </span>
      </div>
    );
  }
  return result;
};
const columnMeta = [
  {
    columnName: 'user',
    order: 1,
    locked: false,
    visible: true,
    customComponent: LinkComponent,
    displayName: 'User ID',
  },
@peterpunk
Copy link

I had the same issue, I found that I had:
<Tabs onSelect={this.handleSelect} selectedIndex={0}>

The problem was the selectedIndex={0} I hope this will solve your issue.

@deepaksisodiya
Copy link

Thanks @peterpunk
You solve my problem :)

@deepaksisodiya
Copy link

Hey, i got this problem,
removing the selectedIndex={0} is not a solution,
You need to set it by state, like

selectedIndex={this.state.selectedTab}

also initialise selectedTab state to your preferred tab.

then on onSelect={this._handleSelect} event of Tabs, set the selectedTab again.

_handleSelect = (index, last) => {
console.log('Selected tab: ' + index + ', Last tab: ' + last);
this.setState({
selectedTab: index
});
};

by doing this, on tab it will not move to another tab by click event :)

@mziwisky
Copy link

fyi, what you want is "Controlled Component" behavior -- see https://facebook.github.io/react/docs/forms.html#controlled-components

I have an outstanding PR to implement this, #80

@jeffreygnatek
Copy link

works for me, thank you @peterpunk

@danez danez added the bug label Jul 1, 2016
@danez danez mentioned this issue Apr 13, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants