Select
Select component is part of the Primer ViewComponents forms framework. If you are building a form, please consider using the framework instead of this standalone component.Description
Select lists are single-line text inputs rendered as <select> tags in HTML.
Arguments
| Name | Default | Description |
|---|---|---|
size | SymbolThe size of the field. One of | |
name | StringValue for the HTML name attribute. | |
id | StringValue for the HTML id attribute. | |
class | StringCSS classes to include in the input's HTML | |
classes | ArrayCSS classes to include in the input's HTML | |
caption | StringA string describing the field and what sorts of input it expects. Displayed below the input. | |
label | StringLabel text displayed above the input. | |
visually_hide_label | BooleanWhen set to | |
disabled | BooleanWhen set to | |
hidden | BooleanWhen set to | |
invalid | BooleanIf set to | |
validation_message | StringA string displayed between the caption and the input indicating the input's contents are invalid. This option is, by default, set to the first Rails validation message for the input (assuming the form is associated with a model object). Use | |
label_arguments | HashAttributes that will be passed to Rails' | |
scope_name_to_model | BooleanDefault | |
scope_id_to_model | BooleanDefault | |
required | BooleanDefault | |
aria | HashKey/value pairs that represent Aria attributes and their values. Eg. | |
data | HashKey/value pairs that represent data attributes and their values. Eg. | |
system_arguments | HashA hash of attributes passed to the underlying Rails builder methods. These options may mean something special depending on the type of input, otherwise they are emitted as HTML attributes. See the Rails documentation for more information. In addition, the usual Primer utility arguments are accepted in system arguments. For example, passing | |
multiple | BooleanIf set to true, the selection will allow multiple choices. | |
include_blank | Boolean, StringIf set to true, an empty option will be created. If set to a string, the string will be used as the option's content and the value will be empty. | |
prompt | StringCreate a prompt option with blank value and the text asking user to select something. |
Methods
option(label: String, value: String)
Adds an option to the list.
Parameters
| Name | Default | Description |
|---|---|---|
label | StringThe user-facing label for the option. | |
value | StringThe value sent to the server on form submission. |