你链接到的文档似乎有你要找的答案。
你应该能维持当地的一些州,
this.state.open
,并将其作为
expanded
支撑到面板上。
class Example extends React.Component {
constructor(props, context) {
super(props, context);
this.state = {
// to share the state, we must maintain it ourselves
open: true
};
}
render() {
const iconClass = this.state.open
? 'fa-angle-double-down'
: 'fa-angle-double-right';
return (
<Panel id="example-1" expanded={this.state.open}>
<Panel.Heading>
<Panel.Title
onClick={() => this.setState({ open: !this.state.open})}>
This is the title of the panel
<i className={iconClass} />
</Panel.Title>
</Panel.Heading>
<Panel.Collapse>
<Panel.Body>
This is the body of the panel
</Panel.Body>
</Panel.Collapse>
</Panel>
);
}
}