Sha256: 3afcb53d0a04d9b5a7a12ec81684ed9686f3d207d475c6a4a003dbf0c80411b8

Contents?: true

Size: 1.32 KB

Versions: 41

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module Ariadne
  module Form
    class BaseInputComponent < Ariadne::BaseComponent
      option :required, optional: true
      option :caption, optional: true

      def add_label_classes(*class_names)
        # label_arguments[:class] = merge_class_names(
        #   label_arguments[:class], *class_names
        # )
      end

      def label_arguments
        {}
      end

      def hidden?
        !!html_attrs[:hidden]
      end

      def full_width?
        @full_width
      end

      # Whether or not to wrap the component in a FormControl, which renders a
      # label above and validation message beneath the input.
      def form_control?
        html_attrs.delete(:form_control) { true }
      end

      private def before_render
        # make sure to evaluate the component's content block so slots are defined
        content

        @input_attributes = {
          aria: {},
        }

        ids = [].tap do |memo|
          memo << @validation_id if @validation_message
          memo << @caption_id if @init_caption || caption?
        end

        return if ids.empty?

        @input_attributes[:aria][:describedby] = ids.join(" ")
      end

      private def caption?
        @caption.present?
      end

      private def required?
        @required.present?
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
ariadne_view_components-0.0.88 app/components/ariadne/form/base_input_component.rb
ariadne_view_components-0.0.87 app/components/ariadne/form/base_input_component.rb
ariadne_view_components-0.0.86.9 app/components/ariadne/form/base_input_component.rb
ariadne_view_components-0.0.86.8 app/components/ariadne/form/base_input_component.rb
ariadne_view_components-0.0.86.7 app/components/ariadne/form/base_input_component.rb
ariadne_view_components-0.0.86.6 app/components/ariadne/form/base_input_component.rb
ariadne_view_components-0.0.86.5 app/components/ariadne/form/base_input_component.rb
ariadne_view_components-0.0.86.4 app/components/ariadne/form/base_input_component.rb
ariadne_view_components-0.0.86.3 app/components/ariadne/form/base_input_component.rb
ariadne_view_components-0.0.86.2 app/components/ariadne/form/base_input_component.rb
ariadne_view_components-0.0.86.1 app/components/ariadne/form/base_input_component.rb
ariadne_view_components-0.0.86 app/components/ariadne/form/base_input_component.rb
ariadne_view_components-0.0.85 app/components/ariadne/form/base_input_component.rb
ariadne_view_components-0.0.84 app/components/ariadne/form/base_input_component.rb
ariadne_view_components-0.0.83.3 app/components/ariadne/form/base_input_component.rb
ariadne_view_components-0.0.83.2 app/components/ariadne/form/base_input_component.rb
ariadne_view_components-0.0.83.1 app/components/ariadne/form/base_input_component.rb
ariadne_view_components-0.0.83 app/components/ariadne/form/base_input_component.rb
ariadne_view_components-0.0.82 app/components/ariadne/form/base_input_component.rb
ariadne_view_components-0.0.81 app/components/ariadne/form/base_input_component.rb