# DropdownMenu

**URL:** <https://forums.fusetools.com/t/dropdownmenu/6288>\
**Category:** Show and Tell\
**Created:** [March 18, 2016, 10:03pm UTC](https://forums.fusetools.com/t/dropdownmenu/6288 "2016-03-18T22:03:06Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Casey\_Williams](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/casey_williams/32/147_2.png) [@Casey\_Williams](https://forums.fusetools.com/u/Casey_Williams)\
**Post date:** [March 18, 2016, 10:03pm UTC](https://forums.fusetools.com/t/dropdownmenu/6288/1 "2016-03-18T22:03:06Z")

</div>

So I’ve adapted the fuse-samples repo [here](https://github.com/fusetools/fuse-samples.git) to make the dropdown menu easier to just import and use quickly in you project. The files are [here](https://github.com/williamshoops96/fuse-dropdown.git)

Please have a look at the readme.

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![Remi\_Pedersen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/remi_pedersen/32/432_2.png) [@Remi\_Pedersen](https://forums.fusetools.com/u/Remi_Pedersen)\
**Post date:** [March 21, 2016, 12:03pm UTC](https://forums.fusetools.com/t/dropdownmenu/6288/2 "2016-03-21T12:03:57Z")

</div>

Cool stuff! I took the liberty of moving the thread to Show and Tell. 🙂

---

<div class="post-metadata">

**Author:** ![Donald1](https://avatars.discourse-cdn.com/v4/letter/d/3da27b/32.png) [@Donald1](https://forums.fusetools.com/u/Donald1)\
**Post date:** [March 29, 2016, 4:17pm UTC](https://forums.fusetools.com/t/dropdownmenu/6288/3 "2016-03-29T16:17:11Z")

</div>

This is great but I dont see how this would work in a situation where multiple drowndowns are required without doing a lot of duplication of markup which in turn would make the ux file super bloated.

When will these functionalities be included in the Fuse Core?

---

<div class="post-metadata">

**Author:** ![Anders\_Lassen](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/anders_lassen/32/522_2.png) [@Anders\_Lassen](https://forums.fusetools.com/u/Anders_Lassen)\
**Post date:** [March 29, 2016, 4:20pm UTC](https://forums.fusetools.com/t/dropdownmenu/6288/4 "2016-03-29T16:20:37Z")

</div>

Hi,

You can re-use any UX Markup component by extracting it into a `ux:Class`

---

<div class="post-metadata">

**Author:** ![Casey\_Williams](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/casey_williams/32/147_2.png) [@Casey\_Williams](https://forums.fusetools.com/u/Casey_Williams)\
**Post date:** [March 29, 2016, 4:21pm UTC](https://forums.fusetools.com/t/dropdownmenu/6288/5 "2016-03-29T16:21:15Z")

</div>

I’m not the person to ask about anything to do with what Fuse will include haha! This is just a kind of proof or just an example of how you may encorporate something like a dropdown in your app. And to have multiple dropdowns all you have to do is download the UX file into your project directory and then to use it just call the class : `<DropdownMenu />`

The only thing you might have to is change the name of the Observable that holds the data as they’ll get mixed if you have more than one dropdown.

I’ll fix that now if you like.

---

<div class="post-metadata">

**Author:** ![Edwin\_Reynoso](https://avatars.discourse-cdn.com/v4/letter/e/e99b99/32.png) [@Edwin\_Reynoso](https://forums.fusetools.com/u/Edwin_Reynoso)\
**Post date:** [March 29, 2016, 4:27pm UTC](https://forums.fusetools.com/t/dropdownmenu/6288/6 "2016-03-29T16:27:23Z")

</div>

Haven’t tested this yet, but looking at the code it doesn’t seem that one can easily edit the colors via properties? could you make that possible? or am I missing something?

---

<div class="post-metadata">

**Author:** ![Casey\_Williams](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/casey_williams/32/147_2.png) [@Casey\_Williams](https://forums.fusetools.com/u/Casey_Williams)\
**Post date:** [March 29, 2016, 4:29pm UTC](https://forums.fusetools.com/t/dropdownmenu/6288/7 "2016-03-29T16:29:05Z")

</div>

Which github repo are you looking at? In mine I removed the colours of each item just to make it barebones so others can do whatever they like to it.

---

<div class="post-metadata">

**Author:** ![Edwin\_Reynoso](https://avatars.discourse-cdn.com/v4/letter/e/e99b99/32.png) [@Edwin\_Reynoso](https://forums.fusetools.com/u/Edwin_Reynoso)\
**Post date:** [March 29, 2016, 4:33pm UTC](https://forums.fusetools.com/t/dropdownmenu/6288/8 "2016-03-29T16:33:56Z")

</div>

Lines 24,25,30,37,45 all have set colors

in [https://github.com/williamshoops96/fuse-dropdown/blob/master/DropdownMenu.ux](https://github.com/williamshoops96/fuse-dropdown/blob/master/DropdownMenu.ux)

btw [this line](https://github.com/williamshoops96/fuse-dropdown/blob/master/DropdownMenu.ux#L38) is commented out, should get deleted if not used

It’d be good to be able to:

```auto
<DropdownMenu SelectedColor="..." HoverColor="..." />

```

etc

---

<div class="post-metadata">

**Author:** ![Casey\_Williams](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/casey_williams/32/147_2.png) [@Casey\_Williams](https://forums.fusetools.com/u/Casey_Williams)\
**Post date:** [March 29, 2016, 4:35pm UTC](https://forums.fusetools.com/t/dropdownmenu/6288/9 "2016-03-29T16:35:36Z")

</div>

Okay I understand, I’ll do that now thanks:)

---

<div class="post-metadata">

**Author:** ![Casey\_Williams](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/casey_williams/32/147_2.png) [@Casey\_Williams](https://forums.fusetools.com/u/Casey_Williams)\
**Post date:** [March 29, 2016, 9:21pm UTC](https://forums.fusetools.com/t/dropdownmenu/6288/10 "2016-03-29T21:21:05Z")

</div>

I’ve gone from scratch again to try and make this work. 80% sure it’s probably the wrong way to go about it but this is what I’ve got:

```auto
<Panel ux:Class="DropdownMenu" ux:Name="Menu" >
    <!-- PROPERTIES -->
    <object ux:Property="ListItems" />
    <object ux:Property="Selected" />
    <float4 ux:Property="TextColor" />
    <Brush ux:Property="BackgroundColor" />
    <Brush ux:Property="BorderColor" />
    <Brush ux:Property="HoverColor" />
    <float4 ux:Property="OptionsHeight" />
    <float4 ux:Property="TextSize" />

    <!-- JAVASCRIPT -->
    <JavaScript>
    var Observable = require('FuseJS/Observable');

    </JavaScript>

    <!-- THE LIST PANEL (when dropdown is open) -->
    <Panel ux:InnerClass="DropdownOption" ux:Name="Option" Height="30" >
        <string ux:Property="Text" />
        <Rectangle Layer="Background" Fill="{Property Menu.BackgroundColor}" >
            <Stroke Brush="{Property Menu.BorderColor}" Width="1" />
        </Rectangle>
        <Text FontSize="{Property Menu.TextSize}" TextColor="{Property Menu.TextColor}" Alignment="CenterLeft" Value="{Property Option.Text}" />

        <WhileHovering>
            <Change Menu.BackgroundColor="#000" />
        </WhileHovering>
    </Panel>

    <!-- THE FIRST PANEL (when dropdown is closed) -->
    <Panel ux:InnerClass="DropdownSelectedItem" ux:Name="SelectedItem" Height="40" >
        <string ux:Property="Text" />
        <Text Alignment="CenterLeft" Value="{Property Menu.Selected}" FontSize="{Property Menu.TextSize}" TextColor="{Property Menu.TextColor}" />
        <Panel Layer="Background">
            <Rectangle Fill="{Property Menu.BackgroundColor}" Height="100%" Alignment="Top" />
        </Panel>
    </Panel>

    <!-- PANEL CONTAINING EVERYTHING -->
    <Panel Width="200" Height="40">
        <Rectangle>
            <Stroke Brush="{Property Menu.BorderColor}" Width="1" />
        </Rectangle>
        <DropdownSelectedItem />
        <Clicked>
            <Toggle Target="expandDropdown" />
        </Clicked>

        <WhileTrue ux:Name="expandDropdown">
            <StackPanel Offset="0,40" >
                <Each Items="{Property Menu.ListItems}" >
                    <DropdownOption Text="{name}" />
                </Each>
            </StackPanel>
        </WhileTrue>
    </Panel>

</Panel>

```

I get an error though when I’m previewing that says:

```auto
Type not found:
DropdownMenu.DropdownSelectedItem

```

---

<div class="post-metadata">

**Author:** ![Donald1](https://avatars.discourse-cdn.com/v4/letter/d/3da27b/32.png) [@Donald1](https://forums.fusetools.com/u/Donald1)\
**Post date:** [March 30, 2016, 7:48pm UTC](https://forums.fusetools.com/t/dropdownmenu/6288/11 "2016-03-30T19:48:24Z")

</div>

I was able to do something like this that worked for me.

```auto
<Panel ux:Class="DropdownMenu" >
        <object ux:Property="Options"/>
        <string ux:Property="SelectedText"/>

    <Panel ux:Class="DropdownOption" ux:Name="self" MinHeight="30">
        <string ux:Property="Text" />
        <string ux:Property="ItemName" />
        <Rectangle Layer="Background">
            <SolidColor ux:Name="bgCol" Color="#FBFDFD" />
            <!-- <Stroke Brush="#BFD8DD" Width="1"/> -->
        </Rectangle>
        <Text Alignment="CenterLeft" Value="{Property self.Text}" FontSize="14" Margin="10,0" TextWrapping="Wrap"/>
        <Text Value="{Property self.ItemName}" Visibility="Collapsed"/>

        <WhileHovering>
            <Change bgCol.Color="#D9E1E4" />
        </WhileHovering>
    </Panel>

    <Panel ux:Class="DropdownSelectedItem" ux:Name="self" MinHeight="40">
        <string ux:Property="Text" />
        <Text Alignment="CenterLeft" Value="{Property self.Text}" FontSize="16" Margin="10,0"/>
        <Panel Layer="Background">
            <Rectangle Fill="#FBFDFD" Height="100%" Alignment="Top"/>
        </Panel>
    </Panel>

    <Panel MinHeight="40" >

        <DropdownSelectedItem Text="{Property this.SelectedText}" /> 

        <Clicked>
            <Toggle Target="expandDropdown" />
        </Clicked>

        <WhileTrue ux:Name="expandDropdown">
            <StackPanel Offset="0,40">
                <Each Items="{Property this.Options}">
                    <DropdownOption Text="{text}" ItemName="{name}" Clicked="{onSelected}" />
                </Each>
            </StackPanel>
        </WhileTrue>

        <DropShadow/>
    </Panel>
</Panel>

```

Then use it like

```auto
<DropdownMenu SelectedText="{selectedItem}" Options="{options}"/>

```

---

<div class="post-metadata">

**Author:** ![Casey\_Williams](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/casey_williams/32/147_2.png) [@Casey\_Williams](https://forums.fusetools.com/u/Casey_Williams)\
**Post date:** [March 30, 2016, 7:51pm UTC](https://forums.fusetools.com/t/dropdownmenu/6288/12 "2016-03-30T19:51:59Z")

</div>

Ah I see why mine didn’t work now! Many thanks Donald! Where is the on selected function?

---

<div class="post-metadata">

**Author:** ![Donald1](https://avatars.discourse-cdn.com/v4/letter/d/3da27b/32.png) [@Donald1](https://forums.fusetools.com/u/Donald1)\
**Post date:** [March 30, 2016, 8:00pm UTC](https://forums.fusetools.com/t/dropdownmenu/6288/13 "2016-03-30T20:00:40Z")

</div>

sorry I forgot to post that

```auto
var options = Observable({name:'item1_id', text:'Item 1'},{name:'item2_id', text:'Item 2'});
var selectedItemName = Observable("");
var selectedItemText = Observable("");
var selectedItem = Observable(function(){
  return selectedItemText.value;
});

function onSelected(args){
  selectedItemName.value = args.data.name;
  selectedItemText.value = args.data.text;
}

```

These were defined in the MainView.ux. This was just using the limited knowledge I have on Fuse. Maybe there is a better way to do this. I am open for suggestions. 🙂

---

<div class="post-metadata">

**Author:** ![indra](https://avatars.discourse-cdn.com/v4/letter/i/5f9b8f/32.png) [@indra](https://forums.fusetools.com/u/indra)\
**Post date:** [April 1, 2016, 4:45am UTC](https://forums.fusetools.com/t/dropdownmenu/6288/14 "2016-04-01T04:45:19Z")

</div>

can I have more than 1 dropdown menu on the screen? if can then Should I copy the whole code again to make 2 dropdown menu?

Thank You

---

<div class="post-metadata">

**Author:** ![Edwin\_Reynoso](https://avatars.discourse-cdn.com/v4/letter/e/e99b99/32.png) [@Edwin\_Reynoso](https://forums.fusetools.com/u/Edwin_Reynoso)\
**Post date:** [April 1, 2016, 4:59am UTC](https://forums.fusetools.com/t/dropdownmenu/6288/15 "2016-04-01T04:59:54Z")

</div>

@indra No you would use it like so:

```auto
<DropDown SomeProperty="someValue"></DropDown>

```

Yet those properties I believe are still being worked on, I don’t think he’s updated the code yet so not sure what properties to set, and hopefully he’ll be making some small docs on the properites you can set

---

<div class="post-metadata">

**Author:** ![Casey\_Williams](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/casey_williams/32/147_2.png) [@Casey\_Williams](https://forums.fusetools.com/u/Casey_Williams)\
**Post date:** [April 1, 2016, 7:59am UTC](https://forums.fusetools.com/t/dropdownmenu/6288/16 "2016-04-01T07:59:02Z")

</div>

Yeah Edwin is right. Sorry I haven’t updated the code yet I will give it a go today.

---

<div class="post-metadata">

**Author:** ![Casey\_Williams](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/casey_williams/32/147_2.png) [@Casey\_Williams](https://forums.fusetools.com/u/Casey_Williams)\
**Post date:** [April 1, 2016, 8:57am UTC](https://forums.fusetools.com/t/dropdownmenu/6288/17 "2016-04-01T08:57:26Z")

</div>

So I’m literally finished, apart from there’s a small bug with Fuse that won’t allow it to work haha. I’ll post on here when it does.

---

<div class="post-metadata">

**Author:** ![Edwin\_Reynoso](https://avatars.discourse-cdn.com/v4/letter/e/e99b99/32.png) [@Edwin\_Reynoso](https://forums.fusetools.com/u/Edwin_Reynoso)\
**Post date:** [April 1, 2016, 9:00am UTC](https://forums.fusetools.com/t/dropdownmenu/6288/18 "2016-04-01T09:00:10Z")

</div>

Post it on the github repo, and some small documentation on the README of the repo, then post here that its been updated and complete 🙂

---

<div class="post-metadata">

**Author:** ![Casey\_Williams](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/casey_williams/32/147_2.png) [@Casey\_Williams](https://forums.fusetools.com/u/Casey_Williams)\
**Post date:** [April 1, 2016, 9:05am UTC](https://forums.fusetools.com/t/dropdownmenu/6288/19 "2016-04-01T09:05:27Z")

</div>

Will do 🙂

---

<div class="post-metadata">

**Author:** ![Casey\_Williams](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/casey_williams/32/147_2.png) [@Casey\_Williams](https://forums.fusetools.com/u/Casey_Williams)\
**Post date:** [April 1, 2016, 8:01pm UTC](https://forums.fusetools.com/t/dropdownmenu/6288/20 "2016-04-01T20:01:23Z")

</div>

Finished:) Pretty much as customizable as you get apart from I removed the hover color haha. Check the repo: [https://github.com/shnupta/fuse-dropdown.git](https://github.com/williamshoops96/fuse-dropdown.git)

One other thing I’m working on is getting the selected properties value so you can use it for other things (like send it off in a fetch request or use it with the storage API).
