# Collapsible accordion list with animation

**URL:** <https://forums.fusetools.com/t/collapsible-accordion-list-with-animation/6056>\
**Category:** How-to Discussions\
**Created:** [June 16, 2017, 8:05pm UTC](https://forums.fusetools.com/t/collapsible-accordion-list-with-animation/6056 "2017-06-16T20:05:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matti\_Tihverainen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/matti_tihverainen/32/684_2.png) [@Matti\_Tihverainen](https://forums.fusetools.com/u/Matti_Tihverainen)\
**Post date:** [June 16, 2017, 8:05pm UTC](https://forums.fusetools.com/t/collapsible-accordion-list-with-animation/6056/1 "2017-06-16T20:05:59Z")

</div>

Hello! I have a ScrollView with items and these items contain an x number of child items. I’m trying to make these child items collapsible with animation. The problem is that if I don’t define a preliminary height for the child items, the animation doesn’t work. So far I figured to make this work by calculating the height of the child items in JS (by knowing the number and height of the children), but I was wondering is there a more robust way to make this in UX?

```auto
<App>
  <JavaScript>

    var Observable = require("FuseJS/Observable");

    var items = Observable();

    var children = [1,2,3,4,5];

    for (i=0;i<10;i++) {

      items.add({
        items : children
      });

    }

    module.exports = {
      items : items
    };

  </JavaScript>
  <ScrollView Padding="20">
    <StackPanel ux:Name="Parent">
      <Each Items="{items}">
        <StackPanel>
          <Text Value="PARENT" Padding="5">
            <Clicked>
              <Toggle Target="Reveal" />
            </Clicked>
          </Text>
          <StackPanel Padding="5" ux:Name="Children" Height="160" ClipToBounds="True">
            <WhileTrue ux:Name="Reveal">
              <Change Children.Height="0" Duration="0.25" Easing="QuadraticInOut"/>
              <Change Children.Visibility="Collapsed" Delay="0.25" />
            </WhileTrue>
            <Each Items="{items}">
              <Text Value="CHILD" Padding="5" />
            </Each>
          </StackPanel>
        </StackPanel>
      </Each>
    </StackPanel>
  </ScrollView>
</App>

```

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [June 17, 2017, 8:59am UTC](https://forums.fusetools.com/t/collapsible-accordion-list-with-animation/6056/2 "2017-06-17T08:59:33Z")

</div>

Hi Matti,

there is a `height()` [UX expression function](https://www.fusetools.com/docs/ux-markup/expressions#functions) available that you could use in UX. Alternatively, you could couple a `LayoutAnimation` with a changing `LayoutRole` - look those up in the docs.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![Matti\_Tihverainen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/matti_tihverainen/32/684_2.png) [@Matti\_Tihverainen](https://forums.fusetools.com/u/Matti_Tihverainen)\
**Post date:** [June 17, 2017, 9:30am UTC](https://forums.fusetools.com/t/collapsible-accordion-list-with-animation/6056/3 "2017-06-17T09:30:26Z")

</div>

Thank you! I tried replacing Height=“160” with Height=“height(this)”, but there was still no animation. Is this because the child items are not populated yet?

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [June 17, 2017, 9:39am UTC](https://forums.fusetools.com/t/collapsible-accordion-list-with-animation/6056/4 "2017-06-17T09:39:16Z")

</div>

What you say you did makes no sense.

You should use the `height()` expression to measure the height of an element that only holds the items you want to show/hide; a nested `StackPanel` maybe? And you should only use it on a `Change` modifier, so that the calculation happens when you actually need to deviate from the rest state.

---

<div class="post-metadata">

**Author:** ![Matti\_Tihverainen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/matti_tihverainen/32/684_2.png) [@Matti\_Tihverainen](https://forums.fusetools.com/u/Matti_Tihverainen)\
**Post date:** [June 17, 2017, 10:01am UTC](https://forums.fusetools.com/t/collapsible-accordion-list-with-animation/6056/5 "2017-06-17T10:01:48Z")

</div>

Ok, thank you!

---

<div class="post-metadata">

**Author:** ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)\
**Post date:** [June 17, 2017, 10:01am UTC](https://forums.fusetools.com/t/collapsible-accordion-list-with-animation/6056/6 "2017-06-17T10:01:52Z")

</div>

Here’s something you could do with `LayoutRole` and `LayoutAnimation`. Not perfect, but should be a good start:

```auto
<App>
  <JavaScript>

    var Observable = require("FuseJS/Observable");

    var items = Observable();

    var children = [1,2,3,4,5];

    for (var i=0;i<10;i++) {

      items.add({
        items : children
      });

    }

    module.exports = {
      items : items
    };

  </JavaScript>
  <ScrollView Padding="20">
    <StackPanel ux:Name="Parent">
      <Each Items="{items}">
        <StackPanel ClipToBounds="true">
          <LayoutAnimation>
            <Resize Vector="1" RelativeTo="SizeChange" Duration="0.25" />
            <Move Vector="1" RelativeTo="PositionChange" Duration="0.25" />
          </LayoutAnimation>
          <Text Value="PARENT" Padding="5">
            <Clicked>
              <Toggle Target="Reveal" />
            </Clicked>
            <WhileTrue ux:Name="Reveal">
                <Change Children.LayoutRole="Standard" />
                <Change Children.Visibility="Visible" />
            </WhileTrue>
          </Text>
          <StackPanel Padding="5" ux:Name="Children" LayoutRole="Inert" Visibility="Hidden">
            <Each Items="{items}">
              <Text Value="CHILD" Padding="5" />
            </Each>
          </StackPanel>
        </StackPanel>
      </Each>
    </StackPanel>
  </ScrollView>
</App>

```

---

<div class="post-metadata">

**Author:** ![Matti\_Tihverainen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/matti_tihverainen/32/684_2.png) [@Matti\_Tihverainen](https://forums.fusetools.com/u/Matti_Tihverainen)\
**Post date:** [June 17, 2017, 12:18pm UTC](https://forums.fusetools.com/t/collapsible-accordion-list-with-animation/6056/7 "2017-06-17T12:18:04Z")

</div>

Wow! Thanks a million Uldis!
