Select Edit

A standard but styled select component.

Examples

Installation


  rails generate shadcn-ui select

Usage

<%= render_select name:, selected:, do |select| %>
  <%= select.option value: do %>
  <% end %>
  <%= select.option label:,  value: %>
<% end %>

The Select component introduces:

  • app/helpers/components/select_helper.rb
  • app/components/shadcn/select_component.rb

The select component is implemented as a component object defined in app/components/shadcn/select_component.rb. This ruby class is initialized from the helper defined in app/helpers/components/select_helper.rb, render_select.

The render_select method accepts a name keyword argument for the name of the form field. An optional argument of selected can contain the value of the option to be selected by default.

render_select yields an instance of the Shadcn::SelectComponent that can be used to build options for the select. option on the component instance accepts a label argument for the label text to be displayed for the option whose value will be the value on the component instance yields a new option object that accepts a label and value argument. option also accepts a block that can be used to create the label.