Class: SegmentedControlInput

Inherits:
SimpleForm::Inputs::CollectionRadioButtonsInput
  • Object
show all
Defined in:
lib/generators/rolemodel/simple_form/templates/app/inputs/segmented_control_input.rb

Overview

SegmentedControlInput is a custom input type for SimpleForm that renders a radio group as an optics (v2.2.0+) segmented control

Options:

:size (:small, :medium, :large) - renders the control at different sizes
:full_width - renders the control to take the full width of its container

Usage: <%= f.input :my_field, as: :segmented_control, collection: collection_options %> <%= f.input :my_field, as: :segmented_control, collection: collection_options, size: :small %> <%= f.input :my_field, as: :segmented_control, collection: collection_options, disabled: true %> <%= f.input :my_field, as: :segmented_control, collection: collection_options, full_width: true %>

Instance Method Summary collapse

Instance Method Details

#input_html_classesObject



34
35
36
# File 'lib/generators/rolemodel/simple_form/templates/app/inputs/segmented_control_input.rb', line 34

def input_html_classes
  super.push('segmented-control__input')
end

#input_html_optionsObject



28
29
30
31
32
# File 'lib/generators/rolemodel/simple_form/templates/app/inputs/segmented_control_input.rb', line 28

def input_html_options
  super.tap do |options|
    options[:class].delete('form-control')
  end
end

#input_optionsObject



19
20
21
22
23
24
25
26
# File 'lib/generators/rolemodel/simple_form/templates/app/inputs/segmented_control_input.rb', line 19

def input_options
  options = super
  options[:item_wrapper_tag] = false
  options[:collection_wrapper_tag] = 'div'
  options[:collection_wrapper_class] = collection_wrapper_classes
  options[:item_label_class] = 'segmented-control__label'
  options
end

#input_typeObject



15
16
17
# File 'lib/generators/rolemodel/simple_form/templates/app/inputs/segmented_control_input.rb', line 15

def input_type
  'radio_buttons'
end