Giter Site home page Giter Site logo

Comments (6)

shepherdwind avatar shepherdwind commented on June 6, 2024

都是通过 prop 控制的,没有这种直接 set 值的,不需要直接 set 的。

from collapse.

qubaomingg avatar qubaomingg commented on June 6, 2024

当需要手动设置 activeKey 的场景呢?有没有一些方法?

from collapse.

shepherdwind avatar shepherdwind commented on June 6, 2024

设置 prop 一个方式就够了,以前 dialog 组件还有 hide 方法的,新版的都没有了。https://github.com/react-component/dialog 如果想关闭弹窗,只能设置 visible 属性了。方法调用的方式不好,得 state 和 prop 混用,统一一种方式比较好理解。

from collapse.

jorisw avatar jorisw commented on June 6, 2024

If I may continue this discussion in English, I'm having trouble setting the activeKey through a user action that results in a setState(). My code:

<Collapse
     activeKey={this.state.activePanel ? this.state.activePanel : 'fullDetails'}
     defaultActiveKey="fullDetails"
     accordion={true} >
        <Panel header="Full Details" key="fullDetails">
...
        </Panel>
        <Panel header="Speakers" key="speakers">
...
        </Panel>
...
openPanel(key){
      this.setState({activePanel:key});
}

Now, when I call openPanel('speakers'), all the panels close, but the one with key speakers doesn't open.

What is the right way to open a panel from the parent component?

from collapse.

shepherdwind avatar shepherdwind commented on June 6, 2024

@jorisw there is an example http://react-component.github.io/collapse/examples/simple.html , and you can actvie panel this way

  setActivityKey() {
    this.setState({
      activeKey: ['2'],
    });
  },

And triggered by button

      <button onClick={this.setActivityKey}>active header 2</button>

I try to change ['2'] to '2' the code just run ok, so I think you code should work fine two.

Maybe you should fork my sample repo https://github.com/shepherdwind/sample-collapse (flow the readme.md step) , and write you code , so I can reproduce you problem.

from collapse.

jorisw avatar jorisw commented on June 6, 2024

You're right it works. Apologies. The problem was in my code.

from collapse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.