Skip to Main Content

Dropdown menus

A dropdown menu lets a user choose an option from a list of mutually exclusive predefined choices.

Use when:

  • Users need to choose a single option from a list of mutually exclusive options.
  • Users need to choose from a large data set that would be impractical for a group of radio buttons.
  • Users need to change a default option.
  • Users are able to choose 2 options from a list of checkboxes in a dropdown menu.

Interactive component

Error message goes here

Customized Drop Down menu

HTML, CSS and JS

Angular

<mat-select> is a form control for selecting a value from a set of options, similar to the native <select> element. You can read more about selects in the Material Design spec. It is designed to work inside of a <mat-form-field> element.

To add options to the select, add <mat-option> elements to the <mat-select>. Each <mat-option> has a value property that can be used to set the value that will be selected if the user chooses this option. The content of the <mat-option> is what will be shown to the user.

Angular Material also supports use of the native <select> element inside of <mat-form-field>. The native control has several performance, accessibility, and usability advantages. See the documentation for form-field for more information.

To use a native select inside <mat-form-field>, add the matNativeControl attribute to the <select> element.



Mendix

Dropdowns are an out-of-the-box functionality.

You simply need to select the Dropdown option from the toolbox on the right.

The styles for Dropdowns should automatically be applied along with the styles for their error states.

The Mendix toolkit can be found here.

Library integration

Use the codes below to add this component to your project. Download the latest version of the library to easily implement our full range of components.

Angular

Step 1. Install

Execute the following command to install this component.

npm i [NPM-PLACE-HOLDER]/ds-dropdown

Step 2. Import

Import the following into your app.module.ts file.

import { DsDropdownModule } from 'ds-dropdown';

Code snippet

<cpc-ds-dropdown
    labelText="Default State"
    labelId="dropdown-label"
    [selectOptions]="selectOptions"
    [selected]="selected"
    [control]="selectFormControl"
    errorMsgRequired="Please select an option">
</cpc-ds-dropdown>
Properties
Name Type Default Description
labelId string LabelId

Dropdown menu label id.

labelText string Default label

Text for dropdown menu label. The language service will be used to pass the EN or FR text

selectOptions array  

Dropdown menu options and values



interface SelectOptions {
  name: string;
  value: string;
}

selectOptions: SelectOptions[] = [
 { name: '---', value: '' },
 { name: 'Dog', value: 'Woof!' },
 { name: 'Cat', value: 'Meow!' },
 { name: 'Cow', value: 'Moo!' },
 { name: 'Fox', value: 'Wa-pa-pa-pa-pa-pa-pow!' }
];
selected string  

Selected value for the dropdown menu

errorMsgRequired string Please select an option.

Error message for the dropdown menu

control Form control  

FormControl for the dropdown menu

selectFormControl = new FormControl(this.selectOptions[0].value, Validators.required);

HTML

Step 1: Import CSS

Import the following in your theme or page.

<link type="text/css" href="[CSS-PLACE-HOLDER]" rel="stylesheet">

Step 2: Import JS and Initialize the component

<script src="[JS-PLACE-HOLDER]"></script> 
<script>DSCpcSelects.init();</script>

Code snippet

<label id="custom-dropdown-label">Choose year</label>
<select 
    id="custom-dropdown" 
    aria-labelledby="custom-dropdown-label errMsg1" 
    aria-invalid="true" 
    class="ds-cpc-control-select__tpl error" 
    style="display: none;">
 <option selected="selected" value="">Select year</option>
 <option value="2013">2013</option>
 <option value="2012">2012</option>
 <option value="2011">2011</option>
</select>

<div id="errMsg1" class="ds-error">Error message goes here</div>

General guidelines

Dropdown menu display a list of options that the user can select. It consists of a dropdown menu label, input field, input field text and the menu options.

Dropdown menus should be used when there are between 6 and 15 options to display. Keep dropdowns succinct to avoid scrolling. The scrollbar should be persistent. Try to let users see all the available options up front.

Consider using radio buttons or checkboxes if you have less than 6 options.

In the case of more than 15 options, consider using an open input field (e.g. asking for birth year). You can also let users narrow in on menu options by typing letters. For example, if they want to choose “France”, they can click on the menu field and start typing “F, R” to jump to “France” in the list.

Ordering the menu items

Use context to order the options in a dropdown menu. When contextual organization isn’t available, alphabetize the options or order them on a scale (e.g. youngest to oldest when selecting an age range.)

  • When possible, offer a neutral option (e.g. “None”) in case no options apply to the user.

Positioning

Dropdown menus are stacked on a form. In cases where the dropdown menus are related information, place them side by side (for example, selecting a time range).

Positioning

Labels

Place a descriptive label above the dropdown menu to clearly let users know what options to expect. This also keeps the user focused on the task they’re trying to complete.

Responsive design

Dropdown menu UI is applied the same way consistently across different devices.

Work with your writer to keep text short and concise.

If you have text that is too long to be displayed in full on a smaller device, truncate the text using an ellipsis. The truncation generally happens automatically for menu items at around 36 characters (depending on a user’s mobile device).

Interaction

States

A dropdown consists of an interactive header element that shows the selected option and the flyout element, which shows the available options.


  1. Default
    The default state is how the dropdown menu appears before users make a selection.

    In some cases, you may include a preselected option in the menu, but only if you are certain most users will choose that response.

  2. Focus
    Dropdown menus have a field focus, and a menu focus.

    Field focus activates when a user navigates to a dropdown component. This state activates by wrapping the dropdown field in a box, indicating that further interaction will open it.

    Menu focus activates after opening a dropdown by highlighting the currently selected menu item. Using the keyboard to navigate items will move the focus state accordingly.

  3. Hover
    When a mouse is used to hover over a menu item, it will be highlighted.
  4. Disabled
    In the disabled state, a dropdown is visible but cannot be interacted with. Faded colours are used to distinguish disabled dropdowns from active ones.

Default

Default

Field focus

Field focus

Menu focus / hover

Menu focus/hover

Disabled

Default

Feedback

Error messages

Error message appears under the dropdown menu.

Error messages

Accessibility considerations

Keyboard accessibility

Users navigate to dropdowns using tab, accessing and navigating options using arrow keys. Enter or spacebar will confirm their selection.

Design specs

For all screen sizes.

Dropdown menu

Dropdown spacing requirements

Error message

Error message text

General guidelines

Use clear, concise and descriptive language to help the user select an option from the dropdown menu. Expect users to simply scan the list items. Use a single line of text for each option.

  Guidelines Examples
Recommended length Use as needed to complete the thought but try to keep it to one line
Line wrap Avoid
Phrasing Short phrases that explain each option
Case Sentence case

Dos and don’ts

Secondary label

Include a meaningful secondary label in the menu itself to prompt an action. This label should be visible in the menu before the user clicks to expand it.

  • Select province
  • Select

Ordering the options

Use context to order the options in a dropdown menu logically. When relevance or frequency isn’t applicable, alphabetize the options or order them on a scale.

Neutral option

When possible, offer a neutral option in the menu for cases when no options apply to the user.

  • How would you rate your overall satisfaction with the Canada Post mobile app?

  • What’s the primary reason why you’re using the app today?

Guidelines

Focus halo

Dropdown menus should have a prominent focus outline when they're focused or hovered. The options in the dropdown menu should also be highlighted when they're focused or hovered.

Keyboard interaction

When the dropdown menu has focus:

  • Alt + down arrow displays the options menu (expanded state)
  • Enter displays the options menu (expanded state)
  • Spacebar displays the options menu (expanded state)
  • Down arrow selects the next option in the Combobox
  • Up arrow selects the previous option in the Combobox

When the dropdown menu is expanded and the options menu has focus:

  • Enter selects the focused option and collapses the options menu
  • End sets the focus on the last option
  • Home sets the focus on the first option
  • Down arrow sets the focus to the next option
  • Up Arrow sets the focus to the previous option

Testing

When testing a dropdown menu, the tester must ensure:

  • The dropdown menu is fully keyboard operable
  • Indications for the focused and hovered states are clear and prominent
  • The dropdown menu has the role of “combobox”
  • The screen reader announces the dropdown label, role, its current value, state (expanded/collapsed), hint text (if present), and error text (if present)