在 React Bootstrap 中更改扩展的手风琴面板的标题样式 [英] Change header style for expanded Panel of Accordion in React Bootstrap

查看:43
本文介绍了在 React Bootstrap 中更改扩展的手风琴面板的标题样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于点击和活动/展开的面板,我想更改 css 样式.那是因为我想切换一个在面板标题内向上或向下指向的图像箭头.

我能够获取打开面板的 eventKey,但我无法使用 panel-heading css 类访问 DOM 元素.

你有什么建议?

谢谢

下面的代码

变成了

 

<div class="panel panel-default"><div class="panel-heading"><h4 role="presentation" class="panel-title"><a role="tab" aria-expanded="false" aria-selected="false">可折叠组项目#1</a></h4></div><div role="tabpanel" class="panel-collapse collapse" aria-hidden="true" style="height: 0px;"><div class="panel-body"><!-- react-text: 36 -->广告素食主义者<!--/react-text -->

<div class="panel panel-default"><div class="panel-heading"><h4 role="presentation" class="panel-title"><a role="tab" aria-expanded="false" aria-selected="false">可折叠组项目#2</a></h4></div><div role="tabpanel" class="panel-collapse collapse" aria-hidden="true" style="height: 0px;"><div class="panel-body"><!-- react-text: 43 -->陈词滥调<!--/react-text -->

解决方案

React Bootstrap Panel 接受一个节点作为标题使用(每个:https://github.com/react-bootstrap/react-bootstrap/blob/v0.20.1/src/Panel.js#L144http://react-bootstrap.github.io/components.html#panels-props),因此您可以将具有适当 onClick 处理程序的内容作为标题传递给它,例如:

For the clicked and active/expanded panel I would like to change the css style. That's because I would like to toggle an image arrow that points up or down inside the header of the panel.

I'm able to get the eventKey of the open panel, but I'm not able to reach the DOM element with the panel-heading css class.

What do you suggest?

Thanks

Code below

<Accordion onSelect={this.handleSelect} >
  <Panel header="Collapsible Group Item #1" eventKey="1">
    Ad vegan
  </Panel>
  <Panel header="Collapsible Group Item #2" eventKey="2">
    Cliche docet
  </Panel>
</Accordion>

That becomes

    <div role="tablist" class="panel-group">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4 role="presentation" class="panel-title"><a role="tab" aria-expanded="false" aria-selected="false">Collapsible Group Item #1</a></h4></div>
            <div role="tabpanel" class="panel-collapse collapse" aria-hidden="true" style="height: 0px;">
                <div class="panel-body">
                    <!-- react-text: 36 -->Ad vegan
                    <!-- /react-text -->
                </div>
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4 role="presentation" class="panel-title"><a role="tab" aria-expanded="false" aria-selected="false">Collapsible Group Item #2</a></h4></div>
            <div role="tabpanel" class="panel-collapse collapse" aria-hidden="true" style="height: 0px;">
                <div class="panel-body">
                    <!-- react-text: 43 -->Cliche docet
                    <!-- /react-text -->
                </div>
            </div>
        </div>
    </div>

解决方案

The React Bootstrap Panel accepts a node to use as a header (per: https://github.com/react-bootstrap/react-bootstrap/blob/v0.20.1/src/Panel.js#L144 and http://react-bootstrap.github.io/components.html#panels-props), so you can pass in something with the appropriate onClick handler to it as a header, perhaps something like:

<Accordion onSelect={this.handleSelect} >
  <Panel header={<div onClick={() => {console.log('Clicked')}}>"Collapsible Group Item #1"</div} eventKey="1">
    Ad vegan
  </Panel>
  <Panel header="Collapsible Group Item #2" eventKey="2">
    Cliche docet
  </Panel>
</Accordion>

这篇关于在 React Bootstrap 中更改扩展的手风琴面板的标题样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆