title: Angular Material Expansion Panels: How to expand initially, but then let the user expand/collapse as they please
body: <p>I have an expansion panel that contains a list of data. When the component loads, I want the panel to be expanded if the length of its data is 0, and collapsed if the length of its data is more than 0. </p>
  
  <p>After initializing, I want the panel to only expand or collapse if the user clicks on it. So if the length of the panel's data changes from 0 to 1, I don't want the panel to then collapse, I want it to stay open.
  The problem is that when I use the expansion panel's [expanded] input, it keeps checking the condition, so when the length of the data changes it expands or collapses even if the user didn't click on it.</p>
  
  <pre><code>&lt;mat-expansion-panel [expanded]="!item.data.length"&gt;
    &lt;mat-expansion-panel-header&gt;
      &lt;mat-panel-title&gt;
        Item with data
      &lt;/mat-panel-title&gt;
    &lt;/mat-expansion-panel-header&gt;
    &lt;div *ngFor="let data of item.data"&gt;
      {{data.name}}
    &lt;/div&gt;
    &lt;button (click)="addDataToItem()"&gt;ADD DATA&lt;/button&gt;
  &lt;/mat-expansion-panel&gt;
  
  </code></pre>
  
  <p><strong>Desired results:</strong> The expansion panel is initially expanded if <code>item.data.length</code> is 0, and initially collapsed if <code>item.data.length</code> is more than 0. Then, if the user clicks the ADD DATA button, the expansion panel stays opened.</p>
  
  <p><strong>Actual results:</strong> The expansion panel is initially expanded if the <code>item.data.length</code> is 0, and collapsed if it is more than 0. But if the user clicks ADD DATA, the </p>
  
  <p>panel closes because the length is more than 0.</p>
  
  <p>Here is a an <a href="https://stackblitz.com/edit/angular-lhvysp" rel="nofollow noreferrer">example</a> of the behavior.  </p>
  
  <p>Notice how the panel is initially expanded because the length is 0, but then when you click ADD DATA, it collapses because the length is 1. I would like it to stay open.</p>