Class: Primer::Alpha::ActionList::FormWrapper
- Inherits:
-
Component
- Object
- ViewComponent::Base
- Component
- Primer::Alpha::ActionList::FormWrapper
- Defined in:
- app/components/primer/alpha/action_list/form_wrapper.rb
Overview
Utility component for wrapping ActionLists or individual ActionList::Items in forms.
Constant Summary collapse
- DEFAULT_HTTP_METHOD =
:get
- HTTP_METHOD_OPTIONS =
[ DEFAULT_HTTP_METHOD, :post, :patch, :put, :delete, :head ].freeze
Constants inherited from Component
Component::INVALID_ARIA_LABEL_TAGS
Constants included from Status::Dsl
Constants included from ViewHelper
Constants included from TestSelectorHelper
TestSelectorHelper::TEST_SELECTOR_TAG
Constants included from FetchOrFallbackHelper
FetchOrFallbackHelper::InvalidValueError
Constants included from Primer::AttributesHelper
Primer::AttributesHelper::PLURAL_ARIA_ATTRIBUTES, Primer::AttributesHelper::PLURAL_DATA_ATTRIBUTES
Instance Method Summary collapse
- #form_required? ⇒ Boolean
- #get? ⇒ Boolean
-
#initialize(list:, action: nil, **form_arguments) ⇒ FormWrapper
constructor
A new instance of FormWrapper.
- #render_inputs? ⇒ Boolean
Methods inherited from Component
Methods included from JoinStyleArgumentsHelper
Methods included from TestSelectorHelper
Methods included from FetchOrFallbackHelper
#fetch_or_fallback, #fetch_or_fallback_boolean, #silence_deprecations?
Methods included from ClassNameHelper
Methods included from Primer::AttributesHelper
#aria, #data, #extract_data, #merge_aria, #merge_data, #merge_prefixed_attribute_hashes
Methods included from ExperimentalSlotHelpers
Methods included from ExperimentalRenderHelpers
Constructor Details
#initialize(list:, action: nil, **form_arguments) ⇒ FormWrapper
Returns a new instance of FormWrapper.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/components/primer/alpha/action_list/form_wrapper.rb', line 18 def initialize(list:, action: nil, **form_arguments) @list = list @form_arguments = form_arguments # When a form is inside a menu, suppress form semantics. # Otherwise, NVDA will miscount menu items. @form_arguments[:html] ||= {} @form_arguments[:html][:role] = :none @action = action @http_method = extract_http_method(@form_arguments) name = @form_arguments.delete(:name) value = @form_arguments.delete(:value) || name inputs = @form_arguments.delete(:inputs) || [] # For the older version of this component that only allowed you to # specify a single input if inputs.empty? inputs << { name: name, value: value, **(@form_arguments.delete(:input_arguments) || {}) } end @inputs = inputs.map do |input_data| input_data = input_data.dup input_data[:type] ||= :hidden input_data[:data] ||= {} input_data[:data][:list_item_input] = true input_data end end |
Instance Method Details
#form_required? ⇒ Boolean
57 58 59 |
# File 'app/components/primer/alpha/action_list/form_wrapper.rb', line 57 def form_required? @action && !get? end |
#get? ⇒ Boolean
53 54 55 |
# File 'app/components/primer/alpha/action_list/form_wrapper.rb', line 53 def get? @http_method == :get end |
#render_inputs? ⇒ Boolean
61 62 63 |
# File 'app/components/primer/alpha/action_list/form_wrapper.rb', line 61 def render_inputs? @inputs.present? end |