Skip to content

Conversation

@lishengzxc
Copy link

No description provided.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.8%) to 93.694% when pulling 57c9d58 on lishengzxc:master into 30a7dac on react-component:master.

if (!('activeKey' in this.props)) {
this.setState({ activeKey });
this.setState({ activeKey }, () => {
this.props.onChange(this.props.accordion ? activeKey[0] : activeKey);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why nope?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#78

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果有问题,需要给出具体问题的描述和重现。

Copy link
Author

@lishengzxc lishengzxc Dec 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我有一个非React的组件:

class NoReactComponent { 
  constructor(container) {}
}

然后在Collapse中使用(非受控形式):

class App extends React.Component {

  collapseOnChange = (keys) => {
    // 由于目前的 Collapse,在执行 onChange 的时候
    // 未在 this.setState 的回调中,导致我无法在 onChange 的回调中拿到
    // this.refs.noReactComponentContainer
    // 当然,我可以为 NoReactComponent 通过包装,成为一个 ReactComponent
    // 然后
    // ```
    // <Panel header="This is panel header 1" key="1">
    //  <NoReactComponentToReactComponent />
    // </Panel>
    // ```
    // 或者
    // <Panel header="This is panel header 1" key="1">
    //   <div ref={noReactComponentContainer => { this.noReactComponentInstance = new NoReactComponent(noReactComponentContainer); }}></div>
    // </Panel>
    // 
    // 但是我觉得哪怕从语义上来说也应该在 this.setState 后 执行 onChange 会合适一点
    // 我想 我和 https://github.com/react-component/collapse/issues/78 并不同
    // 你可以仔细看下我的 PR 的 if else,都会执行 onChange

    if (keys.indexOf('1') !== -1) {
      this.noReactComponentInstance = new NoReactComponent(this.refs.noReactComponentContainer);
    } else {
      delete this.noReactComponentInstance;
    }
  }

  render() {
    return (
      <Collapse
        onChange={this.collapseOnChange}
      >
        <Panel header="This is panel header 1" key="1">
          <div ref="noReactComponentContainer"></div>
        </Panel>
        <Panel header="This is panel header 2" key="2">
          <div></div>
        </Panel>
      </Collapse>
    )
  }
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

试试 <Collapse destroyInactivePane={false}>

@benjycui benjycui closed this Dec 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants