Dropdown

Defines different styles for a toggleable dropdown.

Usage

Any content, like a button, can toggle a dropdown. Just wrap the toggle with a <div> element and add the data-f-dropdown attribute. Add the .f-dropdown class to a child <div> element to create the dropdown itself. A dropdown can be enabled by either hovering or clicking the the toggle.

Data attribute Description
data-f-dropdown Opens the dropdown on hover and adds a little delay, so the dropdown won't disappear immediately, once you stop hovering the toggle.
data-f-dropdown="{mode:'click'}" Opens the dropdown by clicking the toggle. The dropdown closes again on the next click.

IMPORTANT To apply a dropdown, it is important that a parent element has a relative position to align the dropdown properly. Many components create the position context by default, like the Button, Navbar, Subnav and the Tab component.

Example

NOTE In this example we are using a button from the Button component as a toggle.

Markup

<!-- This is the container enabling the JavaScript -->
<div data-f-dropdown>

	<!-- This is the element toggling the dropdown -->
	<div>...</div>

	<!-- This is the dropdown -->
	<div class="f-dropdown">...</div>

</div>

<!-- This is the container enabling the JavaScript in click mode -->
<div data-f-dropdown="{mode:'click'}">

	<!-- This is the element toggling the dropdown -->
	<div>...</div>

	<!-- This is the dropdown -->
	<div class="f-dropdown">...</div>

</div>

Delayed dropdowns in hover mode

You can set a delay parameter in milliseconds to prevent the immediate appearance of the dropdown.

Markup

<div class="f-dropdown" data-f-dropdown="{delay: 1000}">
	...
</div>

Dropdown with navs

A dropdown can contain a nav from the Nav component. Just add the .f-nav class and the .f-nav-dropdown modifier to a <ul> element.

Markup

<div class="f-dropdown">
	<ul class="f-nav f-nav-dropdown">...</ul>
</div>

Alignment modifiers

Add one of the following classes to align the dropdown menu.

Parameter Description
pos:'bottom-left' This is the default behavior. Left aligned dropdown below the toggle.
pos:'bottom-center' Centered dropdown below the toggle.
pos:'bottom-right' Right aligned dropdown below the toggle.
pos:'top-left' Left aligned dropdown above the toggle.
pos:'top-center' Centered dropdown above the toggle.
pos:'top-right' Right aligned dropdown above the toggle.
pos:'left-top' Top aligned dropdown left of the toggle.
pos:'left-center' Centered dropdown left of the toggle.
pos:'left-bottom' Bottom aligned dropdown left of the toggle.
pos:'right-top' Top aligned dropdown right of the toggle.
pos:'right-center' Centered dropdown right of the toggle.
pos:'right-bottom' Bottom aligned dropdown right of the toggle.

Example

Markup

<div data-f-dropdown="{pos:'bottom-center'}"> ... </div>

<div data-f-dropdown="{pos:'top-right'}"> ... </div>

<div data-f-dropdown="{pos:'left-center'}"> ... </div>

<div data-f-dropdown="{pos:'right-top'}"> ... </div>

Justify dropdown

To justify a dropdown, just add the data-f-dropdown="{justify:'#ID'}" attribute. The parent element, to which the dropdown should be justified, needs to have the target id, so the dropdown will expand to the full width of the targeted element.

Example

Markup

<!-- This is the parent element to which the dropdown is being justified -->
<div id="my-id">

	<!-- This is the container enabling the JavaScript -->
	<div class="f-btn-dropdown" data-f-dropdown="{justify:'#my-id'}">

		<!-- This is the element toggling the dropdown -->
		<button class="f-btn">...</button>

		<!-- This is the dropdown -->
		<div class="f-dropdown">...</div>
	</div>
</div>

Automatic dropdown flip

By default, the dropdown flips automatically when it exceeds the viewport's edge. If you want to flip it according to a container's boundary, just add the data-f-dropdown="{boundary:'#ID'}" attribute, using a selector for the container.

Example

Markup

<div id="my-id">
	<div class="f-btn-dropdown" data-f-dropdown="{boundary:'#my-id'}">...</div>
</div>

Grid

You can even place a grid from the Grid component inside a dropdown, which can hold a navigation or any other content. Just wrap the content with a <div> and add the .f-grid class. To optimize the grid for use inside the dropdown, add the .f-dropdown-grid class. Add one of the .f-dropdown-width-* classes to the grid's child elements to multiply the dropdown's width by up to 5.

Example

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt.
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt.

Markup

<div class="f-dropdown f-dropdown-width-2">

	<div class="f-grid f-dropdown-grid">
		<div class="f-width-1-2">
			<ul class="f-nav f-nav-dropdown f-panel">...</ul>
			<div class="f-panel">...</div>
		</div>

		<div class="f-width-1-2">
			<div class="f-panel">...</div>
		</div>
	</div>

</div>

Responsive behavior

In narrower viewports, like phones, there might not be enough space for the dropdown to expand. In that case the dropdown flips its alignment. Should there still not be enough space, the grid columns take up full width and stack vertically inside the dropdown.


Small modifier

By default, the dropdown has a fixed width and the text is wrapping into the next line. If you want your dropdown to be smaller, so that it extends to the width of its content without the text wrapping, add the .f-dropdown-small class. This is useful for button dropdowns.

Example

Markup

<div class="f-dropdown f-dropdown-small">...</div>

Scrollable modifier

To give the dropdown a fixed height and enable its content to scroll, just add the .f-dropdown-scrollable class.

Example

Markup

<div class="f-dropdown f-dropdown-scrollable">...</div>

Dropdowns are an essential part of a navbar from the Navbar component. Just add the .f-dropdown-navbar class to the dropdown, so the dropdown fits perfectly into the navbar.

Example

Markup

<nav class="f-navbar">
	<ul class="f-navbar-nav">

		<!-- This is the container enabling the JavaScript -->
		<li class="f-parent" data-f-dropdown>

			<!-- This is the menu item toggling the dropdown -->
			<a href="">...</a>

			<!-- This is the dropdown -->
			<div class="f-dropdown f-dropdown-navbar">
				<ul class="f-nav f-nav-navbar">
					<li><a href="">...</a></li>
				</ul>
			</div>

		</li>
	</ul>
</nav>

Sometimes you might want to have the functionality of the dropdown but not its styling. In that case just add the .f-dropdown-blank class instead of .f-dropdown.

Example

Title

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

Title

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

Title

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

NOTE In this example we are using a panel from the Panel component to style the dropdown.

Markup

<div class="f-btn-dropdown" data-f-dropdown="{ pos : 'bottom-center' }">
	<button class="f-btn">Hover me <i class="material-icons">arrow_drop_down</i></button>
	<div class="f-dropdown-blank f-panel f-panel-box">
		<h3 class="f-panel-title">Title</h3>
		Lorem ipsum dolor sit amet, consectetur adipisicing elit.
	</div>
</div>

A button from the Button component can be used to trigger a dropdown menu.

Example

Markup

<!-- This is the container enabling the JavaScript -->
<div class="f-btn-dropdown" data-f-dropdown>

	<!-- This is the button toggling the dropdown -->
	<button class="f-btn">...</button>

	<!-- This is the dropdown -->
	<div class="f-dropdown f-dropdown-small">
		<ul class="f-nav f-nav-dropdown">
			<li><a href="">...</a></li>
			<li><a href="">...</a></li>
		</ul>
	</div>

</div>

Dropdown in button groups

Use button groups from the Button component to split buttons into a standard action and a dropdown toggle.

Example

Markup

<div class="f-btn-group">

	<!-- This is a button -->
	<button class="f-btn">...</button>

	<!-- This is the container enabling the JavaScript -->
	<div data-f-dropdown="{mode:'click'}">

		<!-- This is the button toggling the dropdown -->
		<a href="" class="f-btn">...</a>

		<!-- This is the dropdown -->
		<div class="f-dropdown f-dropdown-small">
			<ul class="f-nav f-nav-dropdown">
				<li><a href="">...</a></li>
				<li><a href="">...</a></li>
			</ul>
		</div>

	</div>
</div>

Dropdowns can also be applied to a subnav from the Subnav component.

Example

Markup

<ul class="f-subnav f-subnav-pill">
	<li><a href="">...</a></li>

	<!-- This is the container enabling the JavaScript -->
	<li data-f-dropdown="{mode:'click'}">

		<!-- This is the nav item toggling the dropdown -->
		<a href="">...</a>

		<!-- This is the dropdown -->
		<div class="f-dropdown f-dropdown-small">
			<ul class="f-nav f-nav-dropdown">
				<li><a href="">...</a></li>
			</ul>
		</div>

	</li>
</ul>

Dropdowns can be used on a tab from the Tab component.

Example

Markup

<ul class="f-tab" data-f-tab>
	<li><a href="">...</a></li>

	<!-- This is the container enabling the JavaScript -->
	<li data-f-dropdown="{mode:'click'}">

		<!-- This is the menu item toggling the dropdown -->
		<a href="">...</a>

		<!-- This is the dropdown -->
		<div class="f-dropdown f-dropdown-small">
			<ul class="f-nav f-nav-dropdown">
				<li><a href="">...</a></li>
			</ul>
		</div>
	</li>
</ul>

JavaScript options

This is an example of how to set options via attribute:

data-f-dropdown="{mode:'hover'}"
Option Possible value Default Description
pos string bottom-left Dropdown position
mode hover, click hover Dropdown trigger behaviour
remaintime integer 800 Remain time before auto closing dropdown in hover mode
justify CSS selector false Stretch dropdown width to a specified element
boundary window CSS selector Referenced element to keep dropdowns visibilty
delay integer 0 Delay time in hover mode before a dropdown is shown in ms
hoverDelayIdle integer 250 Is added to the delay time when hovering from one active dropdown to another dropdown (in ms)

Events

You can bind callbacks to following events for custom functionality:

Name Description
show.f.dropdown Triggered on dropdown show
hide.f.dropdown Triggered on dropdown hide
stack.f.dropdown Triggered when a dropdown stacks to fit into screen

Example

$('[data-f-dropdown]').on('show.f.dropdown', function(){
	// custom code...
});