Accordion with panel header in panel header

时间:2016-08-30 09:04:40

标签: javascript reactjs accordion

我想在手风琴的标题中放两个复选框。

EXAMPLE

示例使用标准HTML和JS完成,但我想使用React Bootstrap实现此目的。

给出的例子非常简单。

const accordionInstance = (
  <Accordion>
    <Panel header="Collapsible Group Item #1" eventKey="1">
      Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
    </Panel>
    <Panel header="Collapsible Group Item #2" eventKey="2">
      Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
    </Panel>
    <Panel header="Collapsible Group Item #3" eventKey="3">
      Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
    </Panel>
  </Accordion>
);

ReactDOM.render(accordionInstance, mountNode);

但是要点击header="Collapsible Group Item #1"

两个复选框,不是那么容易。

我尝试过这种方法(删除了div的<Panel>标签),但我不能按照上面的jsfiddle示例来使用它。

<Accordion>
  <div class="panel panel-default">
    <div class="panel-heading">
      <h3 class="panel-title pull-left">Header Text</h3>
      <button class="btn btn-default pull-right">New</button>
    <div class="clearfix"></div>
    </div>
    <div class="panel-body">
      <p>This is the body</p>
    </div>
  </div>
</Accordion>

1 个答案:

答案 0 :(得分:2)

Here is a example of a working version.

我唯一想改进的是你可以点击整个标题面板来展开或折叠手风琴面板。在此阶段,您只能单击标题字来执行此操作。

如果对此有任何建议请赐教。

<div class="bs-example">
    <div class="panel-group" id="accordion">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4 class="panel-title pull-left">
                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne">Demographics</a>
                </h4>
                <div class="pull-right">
                  <label class="checkbox-inline"><input type="checkbox" value=""/>Admission</label>
                  <label class="checkbox-inline"><input type="checkbox" value=""/>Non-Admission</label>
                </div>
                <div class="clearfix"></div>
            </div>
            <div id="collapseOne" class="panel-collapse collapse in">
                <div class="panel-body">
                  <div class="col-sm-6 col-md-6">
                    <label class="checkbox"><input type="checkbox" value="">NHS Number</label>
                    <label class="checkbox"><input type="checkbox" value="">NHS Verification</label>
                    <label class="checkbox"><input type="checkbox" value="">Weight</label>
                    <label class="checkbox"><input type="checkbox" value="">Height</label>
                    <label class="checkbox"><input type="checkbox" value="">Normal BP</label>

                  </div>
                  <div class="col-sm-6 col-md-6">
                    <label class="checkbox"><input type="checkbox" value="">NOK Details</label>
                    <label class="checkbox"><input type="checkbox" value="">NOK Address</label>
                    <label class="checkbox"><input type="checkbox" value="">Ethnic group - Local list</label>
                    <label class="checkbox"><input type="checkbox" value="">Address</label>
                    <label class="checkbox"><input type="checkbox" value="">Language</label>          
                  </div>
                  <div class="col-sm-6 col-md-6">
                    <label for="usr">Custom Name:</label>
                    <input type="text" class="form-control" id="usr">
                  </div>
                </div>
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4 class="panel-title pull-left">
                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">Admission</a>
                </h4>
                <div class="pull-right">
                  <label class="checkbox-inline"><input type="checkbox" value=""/>Admission</label>
                  <label class="checkbox-inline"><input type="checkbox" value=""/>Non-Admission</label>
                </div>
                <div class="clearfix"></div>
            </div>
            <div id="collapseTwo" class="panel-collapse collapse">
                <div class="panel-body">
                  <div class="col-sm-6 col-md-6">
                    <label class="checkbox"><input type="checkbox" value="">ICU dates &amp; times</label>
                    <label class="checkbox"><input type="checkbox" value="">HDU dates &amp; times</label>
                    <label class="checkbox"><input type="checkbox" value="">CCU dates &amp; times</label>
                    <label class="checkbox"><input type="checkbox" value="">ICU/HDU discharge details</label>
                    <label class="checkbox"><input type="checkbox" value="">Time of call for ICU discharges</label>
                    <label class="checkbox"><input type="checkbox" value="">Source of admission</label>
                    <label class="checkbox"><input type="checkbox" value="">Consultant</label>
                    <label class="checkbox"><input type="checkbox" value="">Allow patient renumbering</label>
                    <label class="checkbox"><input type="checkbox" value="">Prior surgery undertaken</label>
                    <label class="checkbox"><input type="checkbox" value="">Planned admission</label>
                  </div>
                  <div class="col-sm-6 col-md-6">
                    <label class="checkbox"><input type="checkbox" value="">Default time of response</label>
                    <label class="checkbox"><input type="checkbox" value="">Original hospital admission date</label>
                    <label class="checkbox"><input type="checkbox" value="">Speciality enterable</label>
                    <label class="checkbox"><input type="checkbox" value="">Scored/Triggered by ward</label>
                    <label class="checkbox"><input type="checkbox" value="">NEWS Score</label>  
                    <label class="checkbox"><input type="checkbox" value="">Called for in first trigger</label>
                    <label class="checkbox"><input type="checkbox" value="">Hospital admission date</label>
                    <label class="checkbox"><input type="checkbox" value="">Location prior to source</label>
                    <label class="checkbox"><input type="checkbox" value="">Location</label>
                    <label class="checkbox"><input type="checkbox" value="">Hospital</label>
                  </div>
                  <div class="col-sm-6 col-md-6">
                    <label for="usr">Custom Name:</label>
                    <input type="text" class="form-control" id="usr">
                  </div>
                </div>
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <h4 class="panel-title pull-left">
                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree">Discharge</a>
                </h4>
                <div class="pull-right">
                  <label class="checkbox-inline"><input type="checkbox" value=""/>Admission</label>
                  <label class="checkbox-inline"><input type="checkbox" value=""/>Non-Admission</label>
                </div>
                <div class="clearfix"></div>
            </div>
            <div id="collapseThree" class="panel-collapse collapse">
                <div class="panel-body">
                    <p>CSS stands for Cascading Style Sheet. CSS allows you to specify various style properties for a given HTML element such as colors, backgrounds, fonts etc. <a href="http://www.tutorialrepublic.com/css-tutorial/" target="_blank">Learn more.</a></p>
                </div>
            </div>
        </div>
    </div>
    <p><strong>Note:</strong> Click on the linked heading text to expand or collapse accordion panels.</p>
</div>