The Select list provides a means to select a single option from a collapsible list of available options within the context of a form. The Select List component utilises the semantic HTML5 select element which is optimal for accessibility and the end user experience.
The use of a select list helps to reduce input errors and screen space.
Problem
>As a customer, I wish to make a single selection from a list of available options.
As a designer, I wish to present the customer with the most appropriate way of selecting a single option from a short (6 to 15) list of options.
Solution
Provide the customer with a dropdown, clearly labelled with the information required.
Guidance
Best practice guidance
Use for single selections with 6 to 15 options.
Use a short, explicit title to clearly label the dropdown list.
Use a short, explicit label for each of the options.
Use additional help text to support the form label if this will help the
user enter the data correctly.
Use sentence case for the title, options and help text, with the
exception of titles or names.
Use reverse pyramid writing, starting with the most important
information first.
Order your results in a way which makes sense to your customers.
Alphabetical is the default order. The order can be adjusted, so
priority or popular options comes first, with the remaining options
ordered alphabetically.
Don’t use where there is a customer benefit to seeing all the available
options up front.
Consider a radio button list or checkbox list if there are fewer
options, or a combo box if there are more.
Consider a Checkbox list or Combobox when users can select more than one
option from a list.
Consider a combo box where formatted search results are required, or
where each option has more than a simple few words to describe it.
Consider placing common options at the beginning of long lists of
options.
The primary content to describe the form control, the label must display a meaningful description to ensure the form control is correctly understood by users.
id
string
true
The unique id of the form control.
onChange
function
true
Fires the onChange event of the select list.
className
string
false
Allows for specific classNames to be set.
options
Object: label | value
true
An array containing objects with value and label strings. This prop populates the option elements within the select list.
name
string
false
The name of the form control.
value
string
false
Displays a pre-defined value for the form control. If no value is set the first option is displayed.
size
oneOf: default | small | large
default
false
Sets the size of the form control and the associated label text, this prop controls the font size and padding of the form control. If not set "default" is output as the default setting.
Sets the width of the form control, this props controls the width of the form control. If not set width defaults to 100%.
containerWidth
boolean
true
Controls where the width is defined - true is for the width applied to the component parent container which then limits the width of the label, form control, error and support text. The default is false which sets the width only on the form control.
required
boolean
true
A boolean that applies an aria-required value on the form control.
declaration
required | option
Displays required or optional text next to the associated label.
disabled
boolean
false
The disabled state of the form control.
error
boolean
false
The error state of the form control.
errorText
string
false
Provides the error message to be presented to users to help them correct the erroneous form control. This value will only be output when the "error" boolean props is set to true.
labelSize
oneOf: default | small | large
default
false
Sets the size of the label, this props controls the font size of the label. If not set "default" is output as the default setting.
labelHidden
boolean
false
false
A boolean that visually hides the form control label. This should only be considered if the form control is clearly described by adjacent content/labels.
labelContext
string
false
Allows for additional instructions to be inserted into the label element, this content is visually hidden and can be used to provide additional context to a form control for assistive technolgy users.
labelAction
function
false
Provides the function to initiate the contextual action.
labelActionText
ReactNode
false
Provides the content of the contextual action.
supportText
string
false
Allows for support text to be displayed underneath the title identifier, this is recommended for additional context is required that will benefit all users. As an example this can be used to convey specific formats like date strings.
ref
string
false
Allows a ref to be set on the form control.
Other attributes
Allowable attributes
The following attributes can be used when required, these attributes are all valid HTML5 attributes.