Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to collapse a panel?

I've been doing a lot of research on this and can't find a good solution. Basically, I have a panel in my app (Panel 2) and would like to collapse it to the left when the button is clicked and if the button gets clicked again then expand it to the right.

Here's my working Code: PLUNKER


  <div fxFlex fxLayout="row" fxLayoutAlign="space-between stretch" style="background-color:green;">
      <div fxFlex [fxShow]="explorerShow"  style="background-color:white;">        
 <div  (click)="toggleDirection()" > <img src="../../../assets/images/button1.png" alt="Button" style = 'float: right'>
 </div>
      Panel 2
 </div>
like image 415
HenryDev Avatar asked Dec 23 '17 00:12

HenryDev


People also ask

What does it mean to collapse a panel?

Enables you to expand or collapse a section that contains a number of views. A collapsible panel can contain other views, such as text boxes or other collapsible panels.

How do I collapse a panel in Bootstrap?

Just add data-toggle="collapse" and a data-target to the element to automatically assign control of one or more collapsible elements. The data-target attribute accepts a CSS selector to apply the collapse to. Be sure to add the class collapse to the collapsible element.

How do you collapse in HTML?

The .collapse class indicates a collapsible element (a <div> in our example); this is the content that will be shown or hidden with a click of a button. To control (show/hide) the collapsible content, add the data-toggle="collapse" attribute to an <a> or a <button> element.

How do you collapse an accordion by default?

To create an accordion that is collapsed by default, we need to set the 'active' property of the jQuery Accordion as false. Syntax: $("#demoAccordion"). accordion({ collapsible: true, active: false});


1 Answers

Use fxHide and [fxShow]="expand" on Panel 2 element

<div class="container">

  <div class="content" fxLayout="row" fxFlexFill>

      <div class="sec1" fxFlex="20%" fxHide [fxShow]="expand">
          SIDEBAR
      </div>
      <div class="sec2" fxFlex="100%">
          BODY
      </div>
  </div>

  <button (click)="expand = !expand">Toggle Sidebar</button>

</div>

Here is a working stackblitz | your plunkr

UPDATE: Here is a stackblitz with animation

like image 125
Murhaf Sousli Avatar answered Sep 22 '22 08:09

Murhaf Sousli