OTTODesign System

ComponentsForm

Dropdown

The dropdown displays multiple options in a compact way. Tapping inside a dropdown shows the options in a native list, from which one is selectable.

Configurator

LiveDropdown: label, selection, hint, error message and state
HTML
<oc-dropdown-v1 label="Land" empty-option hint="Wähle das Land aus, in dem du lebst."><option>Deutschland</option><option>Österreich</option><option>Schweiz</option><option>Frankreich</option><option>Niederlande</option></oc-dropdown-v1>

Usage

Anatomy

1 2 3 4 5
  1. Container
  2. Label
  3. Selection
  4. Chevron
  5. Hint
LiveAnatomy
HTML
<div class="anatomy" style="display:block;max-width:360px;margin:28px auto">
<oc-dropdown-v1 label="Anrede" value="Frau" hint="Für eine persönliche Ansprache."><option>Frau</option><option>Herr</option><option>Divers</option></oc-dropdown-v1>
<span class="anatomy-pin" style="left:-16px;top:35%">1</span>
<span class="anatomy-pin" style="left:7%;top:-18px">2</span>
<span class="anatomy-pin" style="left:22%;top:38%">3</span>
<span class="anatomy-pin" style="left:calc(100% + 16px);top:38%">4</span>
<span class="anatomy-pin" style="left:-16px;top:92%">5</span>
<ol class="anatomy-key"><li data-n="1">Container</li><li data-n="2">Label</li><li data-n="3">Selection</li><li data-n="4">Chevron</li><li data-n="5">Hint</li></ol>

Variants

There are two variants of the dropdown:

  • Default
  • Error: The error variant is not only visualized by the error color but also by an error icon, which is due to accessibility. Additionally, the error should be explained.

Default

Error

LiveDefault and error
HTML
<p class="demo-label">Default</p>
<oc-dropdown-v1 label="Anrede" empty-option hint="Für eine persönliche Ansprache."><option>Frau</option><option>Herr</option><option>Divers</option></oc-dropdown-v1>
<p class="demo-label">Error</p>
<oc-dropdown-v1 label="Anrede" empty-option validation-message="Bitte wähle eine Anrede aus." hint="Für eine persönliche Ansprache."><option>Frau</option><option>Herr</option><option>Divers</option></oc-dropdown-v1>

Hint and error

The dropdown comes with an optional hint. The hint helps the user choosing the correct answer and provides further context. The error is shown additionally above the hint if the user made a wrong input. It helps the user understanding the mistake and fixing the input.

Hint

Error and hint

LiveHint and error
HTML
<p class="demo-label">Hint</p>
<oc-dropdown-v1 label="Land" empty-option hint="Wähle das Land aus, in dem du lebst."><option>Deutschland</option><option>Österreich</option><option>Schweiz</option></oc-dropdown-v1>
<p class="demo-label">Error and hint</p>
<oc-dropdown-v1 label="Land" empty-option validation-message="Bitte wähle ein Land aus, um fortzufahren." hint="Wähle das Land aus, in dem du lebst."><option>Deutschland</option><option>Österreich</option><option>Schweiz</option></oc-dropdown-v1>

Behavior

States

Empty (hover, focus it)

Filled

Disabled, empty

Disabled, filled

LiveStates
HTML
<p class="demo-label">Empty (hover, focus it)</p>
<oc-dropdown-v1 label="Anrede" empty-option hint="Hinweis"><option>Frau</option><option>Herr</option><option>Divers</option></oc-dropdown-v1>
<p class="demo-label">Filled</p>
<oc-dropdown-v1 label="Anrede" value="Frau" hint="Hinweis"><option>Frau</option><option>Herr</option><option>Divers</option></oc-dropdown-v1>
<p class="demo-label">Disabled, empty</p>
<oc-dropdown-v1 label="Anrede" empty-option disabled hint="Hinweis"><option>Frau</option><option>Herr</option><option>Divers</option></oc-dropdown-v1>
<p class="demo-label">Disabled, filled</p>
<oc-dropdown-v1 label="Anrede" value="Frau" disabled hint="Hinweis"><option>Frau</option><option>Herr</option><option>Divers</option></oc-dropdown-v1>

Interaction

When the user chooses an option the label will move to the top left and the selection will be displayed inside the container. Depending on the position of the dropdown, the dropdown can open upward or downward. The dropdown uses the native dropdown list of the operating system.

Tap inside the dropdown, then choose a selection

↓ after the selection

LiveInteraction
HTML
<oc-dropdown-v1 label="Versandart" empty-option hint="Hinweis"><option>Standardversand</option><option>Expressversand</option><option>Wunschtermin</option><option>Abholung im Paketshop</option><option>Abholung in der Filiale</option></oc-dropdown-v1>
<oc-dropdown-v1 label="Versandart" value="Expressversand" hint="Hinweis"><option>Standardversand</option><option>Expressversand</option><option>Wunschtermin</option><option>Abholung im Paketshop</option><option>Abholung in der Filiale</option></oc-dropdown-v1>

Fitting

The width of the dropdown is set to fill-parent by default. The dropdown's height uses fit-content and adapts when a hint or error is visible.

Fills the parent width, height fits the content

LiveFitting
HTML
<p class="demo-label">Fills the parent width, height fits the content</p>
<oc-dropdown-v1 label="Anrede" empty-option hint="Hinweis"><option>Frau</option><option>Herr</option><option>Divers</option></oc-dropdown-v1>

Placement

You can place multiple dropdowns side by side. When placing them horizontally, make sure there is an 8px gap between them. Use a form group to set only one hint and error for horizontally placed dropdowns. Vertically, there should be a 24px gap.

Side by side in a form group, 8px gap

LiveHint and error
HTML
<p class="demo-label">Side by side in a form group, 8px gap</p>
<oc-form-group-v1 orientation="horizontal" flex-behavior="grow" gap="var(--oc-base-dimension-8)" hint="Hinweis" oc-aria-label="Lieferung">
<oc-dropdown-v1 label="Land" empty-option><option>Deutschland</option><option>Österreich</option></oc-dropdown-v1>
<oc-dropdown-v1 label="Versandart" empty-option><option>Standard</option><option>Express</option></oc-dropdown-v1>
</oc-form-group-v1>

Stacked, 24px gap

LiveVertical placement
HTML
<p class="demo-label">Stacked, 24px gap</p>
<oc-form-group-v1 orientation="vertical" gap="var(--oc-base-dimension-24)" oc-aria-label="Lieferung">
<oc-dropdown-v1 label="Land" empty-option hint="Hinweis"><option>Deutschland</option><option>Österreich</option></oc-dropdown-v1>
<oc-dropdown-v1 label="Versandart" empty-option hint="Hinweis"><option>Standard</option><option>Express</option></oc-dropdown-v1>
<oc-dropdown-v1 label="Zustellung" empty-option hint="Hinweis"><option>Bis zur Haustür</option><option>Bis in die Wohnung</option></oc-dropdown-v1>
</oc-form-group-v1>

You can group multiple related dropdowns horizontally, e.g. for choosing the date - though a text field with type date may be appropriate for this task too. Form group can be used to set a hint for all combined form elements.

LiveGroup placement
HTML
<oc-form-group-v1 orientation="horizontal" flex-behavior="shrink" gap="var(--oc-base-dimension-8)" hint="Hinweis" oc-aria-label="Geburtstag" style="justify-content:center">
<oc-dropdown-v1 label="Tag" empty-option style="width:6rem"><option>1</option><option>2</option><option>3</option></oc-dropdown-v1>
<oc-dropdown-v1 label="Monat" empty-option style="width:10rem"><option>Januar</option><option>Februar</option><option>März</option></oc-dropdown-v1>
<oc-dropdown-v1 label="Jahr" empty-option style="width:7rem"><option>1990</option><option>1991</option><option>1992</option></oc-dropdown-v1>
</oc-form-group-v1>

Best practices

DoUse dropdowns when there are five or more options.
CautionIf there are less options consider using radio buttons instead of a dropdown.

Content guidelines

DoUse short, precise labels to describe the selections.
Don'tUse overly descriptive labels to describe the selections.

Accessibility

Implementation

Live demo

Persönliche Daten

Damit wir dich richtig ansprechen und dir zum Geburtstag gratulieren können.

Vorname Nachname

Geburtsdatum

Speichern
LiveReal OTTO components, rendered by the OTTO component runtime
HTML
<div style="max-width:480px;margin:0 auto;display:grid;gap:24px">
<div style="display:grid;gap:4px">
  <p class="oc-headline-100">Persönliche Daten</p>
  <p class="oc-copy-100 oc-text-color-secondary">Damit wir dich richtig ansprechen und dir zum Geburtstag gratulieren können.</p>
<oc-dropdown-v1 label="Anrede" value="Frau"><option>Frau</option><option>Herr</option><option>Divers</option><option>Keine Angabe</option></oc-dropdown-v1>
<oc-form-group-v1 orientation="horizontal" flex-behavior="grow" gap="var(--oc-base-dimension-8)" oc-aria-label="Name">
  <oc-text-field-v1 value="Lara" autocomplete="given-name">Vorname</oc-text-field-v1>
  <oc-text-field-v1 value="Lavendel" autocomplete="family-name">Nachname</oc-text-field-v1>
</oc-form-group-v1>
<div style="display:grid;gap:12px">
  <p class="oc-copy-100"><b>Geburtsdatum</b></p>
  <oc-form-group-v1 orientation="horizontal" flex-behavior="grow" gap="var(--oc-base-dimension-8)" hint="Optional. Wir verwenden es nur für deinen Geburtstagsgruß." oc-aria-label="Geburtsdatum">
    <oc-dropdown-v1 label="Tag" value="14" style="flex:0 1 6rem"><option>12</option><option>13</option><option>14</option><option>15</option></oc-dropdown-v1>
    <oc-dropdown-v1 label="Monat" value="Mai"><option>März</option><option>April</option><option>Mai</option><option>Juni</option></oc-dropdown-v1>
    <oc-dropdown-v1 label="Jahr" value="1991" style="flex:0 1 7rem"><option>1990</option><option>1991</option><option>1992</option></oc-dropdown-v1>
  </oc-form-group-v1>
<oc-button-v1 variant="primary">Speichern</oc-button-v1>

Code

Version Tag Status API
v1 <oc-dropdown-v1> Stable DropdownV1

API

API: <oc-dropdown-v1> (DropdownV1)

The Dropdown component is used to provide a list of selectable options to the user. It can be configured with a label, a hint, an error state, to be required and to be disabled.

Attributes / properties
Attribute Type Default Required Description
variant "default" | "error" "default" no Sets the main styling and behavior of the dropdown.
label string undefined no Sets the text content for the dropdown label to provide a brief description of the input field.
value string undefined no Sets the initial value of the dropdown to the provided value for form processing.
options { label: string; value: string; disabled?: boolean | undefined; }[] [] no Sets the selectable options by providing an array or JSON string. This is an alternative to the default slot. Read more in the section setting options.
hint string undefined no Provides additional information related to the dropdown below the input element.
validation-message string undefined no Provides a validation message related to the dropdown below the input element.

Implicitly sets the dropdown to the error state.
disabled boolean false no Disables the dropdown, preventing user interaction and input.
required boolean false no Marks the input as required for screen readers. Doesn't prevent form submission on its own.
autocomplete
48 values"" | "off" | "on" | "email" | "tel" | "tel-area-code" | "tel-country-code" | "tel-extension" | "tel-local" | "tel-local-prefix" | "tel-local-suffix" | "tel-national" | "additional-name" | "address-level1" | "address-level2" | "address-level3" | "address-level4" | "address-line1" | "address-line2" | "address-line3" | "bday-day" | "bday-month" | "bday-year" | "cc-csc" | "cc-exp" | "cc-exp-month" | "cc-exp-year" | "cc-family-name" | "cc-given-name" | "cc-name" | "cc-number" | "cc-type" | "country" | "country-name" | "current-password" | "family-name" | "given-name" | "honorific-prefix" | "honorific-suffix" | "name" | "new-password" | "one-time-code" | "organization" | "postal-code" | "street-address" | "transaction-amount" | "transaction-currency" | "username"
"off" no Specifies if browsers are permitted to provide assistance in filling out the dropdown. Set to one of the enum values to enable specific autocomplete.
empty-option boolean false no Provides an empty option at the top of the dropdown.
name string undefined no Sets the name tag to identify the dropdown when submitting a form.
oc-aria-label string undefined no Sets the ARIA label of the dropdown.
without-optional-label boolean false no Excludes the automatic "(optional)" label suffix even if the feature toggle is active.
Slots
Slot Required Description
default no Sets the selectable options by providing option elements. This is an alternative to the options attribute. Read more in the section setting options.
Events
Event Detail type Description
oc-property-change OcDropdownV1Events["oc-property-change"] Whenever a property value changes, this event triggers. Use this event to track all property changes within the component.

Refer to the Events documentation for more information.
oc-mount { component: string; } Fired when the component is mounted to the DOM. The event is fired when the onMount hook of the component is called by the runtime.
oc-unmount { component: string; } Fired when the component is unmounted from the DOM. The event is fired when the function returned by the onMount hook of the component is called by the runtime.

Examples

Listed below are the most common variations of the dropdown component as well as specific component variations for different use cases.

Default

The default configuration uses the default variant and an options attribute to pass the options.

HTML
<oc-dropdown-v1 label="Bitte auswählen" name="my-dropdown" empty-option options='[{"label": "Option 1", "value": "value1"}, {"label": "Option 2", "value": "value2"}, {"label": "Option 3", "value": "value3"}]'></oc-dropdown-v1>
With hint

The defaultvariant using the hint attribute to provide additional information.

HTML
<oc-dropdown-v1 label="Label" name="my-dropdown" empty-option hint="Hint" options='[{"label": "label1", "value": "value1"}, {"label": "label2", "value": "value2"}, {"label": "label3", "value": "value3"}]'></oc-dropdown-v1>
Error

The error variant using a red color to indicate an error state and the hint attribute to provide additional information.

HTML
<oc-dropdown-v1 label="Label" name="my-dropdown" empty-option validation-message="Invalid input" hint="Hint" options='[{"label": "label1", "value": "value1"}, {"label": "label2", "value": "value2"}, {"label": "label3", "value": "value3"}]'></oc-dropdown-v1>
Disabled

The default variant using the disabled attribute to disable the dropdown, preventing user interaction.

HTML
<oc-dropdown-v1 label="Label" name="my-dropdown" empty-option disabled hint="Hint" options='[{"label": "label1", "value": "value1"}, {"label": "label2", "value": "value2"}, {"label": "label3", "value": "value3"}]'></oc-dropdown-v1>
Demo alternative way to pass options

A demonstration of how to pass options using the default slot instead of the options attribute.

HTML
<oc-dropdown-v1 label="Label" name="my-dropdown" empty-option hint="Hint">
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
</oc-dropdown-v1>