Use Dropdown...
- To display a list with plain text.
 - To leverage the native browser select functionality.
 - To select a single item from a larger set of items.
 - To submit data within a form.
 
Dropdown is built using the native HTML select element, so the appearance of its Dropdown list is determined by the user's browser and device.
Skin
Default
The default Dropdown is styled like other form elements and displays the first option within the Dropdown list.
The preview has been updated.
Line
skin="line" is deprecated in SWAN v3.3
Use the skin="standard" instead, which aligns with new semantic roles on SWAN components.
The preview has been updated.
Size
size is deprecated in SWAN v3.3
The component now automatically handles sizing based on the selected mode(standardMode/compactMode). Please update your implementation to rely on the new mode-based sizing.
Use size="mini" to reduce the height of a Dropdown.
The "mini" Dropdown should play a supporting role in the layout, ensuring a clear visual hierarchy. This size works well in situations where there is limited vertical space.
The preview has been updated.
Full width
Use fullWidth to grow a Dropdown to fill its container.
The preview has been updated.
With floating label
An alternate way to display the dropdown with the label positioned inside it, above the selection. To achieve that, use the component InputWithFloatingLabel.
The preview has been updated.
Disabled
Usedisabled onDropdown to prevent it from being opened; when it is dependent on a prior user action.
Use disabledon DropdownOption to indicate that individual options are not relevant or available within the user's current context.
The preview has been updated.
Forms: Error messaging, helper text, and external labels
Dropdown errors, helper text, and external labels should use the standard Form component.
Vanilla API
Refer to Form for more details
React API
In React API, use the FormField components to incorporate external labels, error messages, or helper text. These components automatically apply the necessary aria attributes to the Dropdown, eliminating the need for manual handling.g.
Note that FormField components provide minimal styling, and it's recommended to nest FormField within a StandardForm for the desired look.
Inspecting the DOM reveals that FormLabel automatically sets a for attribute to the Dropdown's ID, and the Dropdown's aria-describedby prop is set to the FormHelper's ID.
The preview has been updated.
In the presence of a FormError, the Dropdown automatically adopts an error-state appearance without requiring additional props. Inspecting the DOM reveals that the aria-errormessage and aria-describedby props on the Dropdown are automatically set.
The preview has been updated.
Managing state
As is the case with most form elements, folks often want to "control" this component. Controlling a component means that you take ownership over its state rather than letting the browser manage the state for you. When you control a component, you own the source of truth for the UI. This means that you don't need to query the DOM in order to determine the current value of the element. So, when it comes time to use the value of the element somewhere else (e.g. submitting the selection to a back-end service) you can trust your stored value.
To control a Dropdown, store the selected value (e.g., in React state or a Redux store) and provide a handler to update this value when users interact with the component.
If you don't need to manage the state of the Dropdown, you can omit the value and onChange props, allowing the browser to handle the state. Consider using the defaultValue prop to specify the initial selected value.
Implementation
For the Vanilla API, if your Dropdown is created after the DOMready event, initialize it by triggering an initializeControl event on it.
Avoid placing a Dropdown inside an element that is a table cell or has CSS display: table-cell. This configuration may result in the Dropdown being rendered more narrowly than its actual minimum width.
Accessibility
See accessibility details for Forms.