Form Select

The Select component is a user-friendly form control designed to let users pick an option or multiple options from a set. Upon selection, it presents a dialog showcasing all choices in an easily navigable list, with features like added context messages, error indications, and a disabled mode.


React Component

Variants

Default

The Default variation of the Select component is a simple HTML form element.


Select with Message

The Select component can be used with a message to provide additional context.

The default currency will be used for formatting and calculation purposes.

Error State

The Select component can indicate an error state.

This field is required.

Disabled

The Select component can be marked as disabled. Selects labeled as Disabled will not be submitted in forms.

This field is not available until you select a language.

Sage Component

SageFormSelect
<h2>Variants</h2>

<h3>Default</h3>
<p>The Default variation of the Select component is a simple HTML form element.</p>
<%= sage_component SageFormSelect, {
  name: "Language",
  id: "language",
  select_options: [
    {
      text: "de - German",
      value: "de",
    },
    {
      text: "en - English",
      value: "en",
    },
    {
      text: "es - Spanish",
      value: "es",
    },
    {
      text: "fi - Finnish",
      value: "fi",
    },
    {
      text: "fr - French",
      value: "fr",
    },
  ],
} %>

<%= sage_component SageDivider, {} %>

<h3>Select with Message</h3>
<p>The Select component can be used with a message to provide additional context.</p>

<%= sage_component SageFormSelect, {
  name: "Default Currency",
  select_options: [
    {
      text: "USD - United States Dollar",
      value: "USD",
    },
    {
      text: "AED - United Arab Emirates Dirham",
      value: "AED",
    },
    {
      text: "AFN - Afghan Afghani",
      value: "AFN",
    },
    {
      text: "ALL - Albanian Lek",
      value: "ALL",
    },
  ],
  message: "The default currency will be used for formatting and calculation purposes."
} %>

<%= sage_component SageDivider, {} %>

<h3>Error State</h3>
<p>The Select component can indicate an error state.</p>

<%= sage_component SageFormSelect, {
  name: "Text direction",
  has_error: true,
  select_options: [
    {
      text: "Left to right (ltr)",
      value: "ltr",
    },
    {
      text: "Right to left (rtl)",
      value: "rtl",
    },
  ],
  message: "This field is required."
} %>

<%= sage_component SageDivider, {} %>

<h3>Disabled</h3>
<p>The Select component can be marked as disabled. Selects labeled as Disabled will not be submitted in forms.</p>

<%= sage_component SageFormSelect, {
  name: "Text direction",
  disabled: true,
  select_options: [
    {
      text: "Left to right (ltr)",
      value: "ltr",
    },
    {
      text: "Right to left (rtl)",
      value: "rtl",
    },
  ],
  message: "This field is not available until you select a language."
} %>
Property Description Type Default

disabled

Enabling this property adds the disabled attribute to the component. disabled inputs are not submitted in forms.

Boolean

false

has_error

Enabling this property styles the select in the default danger color theme.

Boolean

false

message

Displays the message text for the component.

String

nil

name

Unique identifier for this component.

String

nil

select_options

An array of items that will serve as the <select>'s <option>s and <optgroup>s.

Array<{
  text: String,
  value: String (optional),
  disabled: Boolean (false),
  selected: Boolean (false),
  group_label: String,
  group_options: Array<{
    text: String,
    value: String (optional),
    disabled: Boolean (false),
    selected: Boolean (false),
    group_label: String (optional),
    group_options: Array (optional),
  }>,
}>

nil

Do
  • Use the sage-btn-group for more than one button to apply spacing
  • If the context does not already provide positioning settings (such as inside a card or panel footer) use the sage-btn-group--align-end to place buttons on the right side of a space.