lib/primer/forms/dsl/input.rb in openproject-primer_view_components-0.23.0 vs lib/primer/forms/dsl/input.rb in openproject-primer_view_components-0.24.0

- old
+ new

@@ -29,11 +29,11 @@ # @!macro [new] form_size_arguments # @param size [Symbol] The size of the field. <%= one_of(Primer::Forms::Dsl::Input::SIZE_OPTIONS) %> # @!macro [new] form_full_width_arguments - # @param full_width [Boolean] When set to `true`, the field will take up all the horizontal space allowed by its container. + # @param full_width [Boolean] When set to `true`, the field will take up all the horizontal space allowed by its container. Defaults to `true`. # @!macro [new] form_system_arguments # @param system_arguments [Hash] A hash of attributes passed to the underlying Rails builder methods. These options may mean something special depending on the type of input, otherwise they are emitted as HTML attributes. See the [Rails documentation](https://guides.rubyonrails.org/form_helpers.html) for more information. In addition, the usual Primer utility arguments are accepted in system arguments. For example, passing `mt: 2` will add the `mt-2` class to the input. See the Primer system arguments docs for details. SPACE_DELIMITED_ARIA_ATTRIBUTES = %i[describedby].freeze @@ -65,11 +65,13 @@ def initialize(builder:, form:, **system_arguments) @builder = builder @form = form @input_arguments = system_arguments + @input_arguments.delete(:id) unless @input_arguments[:id].present? @label_arguments = @input_arguments.delete(:label_arguments) || {} + @label_arguments[:for] = id if id.present? @label_arguments[:class] = class_names( @label_arguments[:class], @input_arguments.fetch(:visually_hide_label, false) ? "sr-only" : nil ) @@ -80,11 +82,11 @@ @label_arguments.delete(:class) if @label_arguments[:class].blank? @caption = @input_arguments.delete(:caption) @validation_message = @input_arguments.delete(:validation_message) @invalid = @input_arguments.delete(:invalid) - @full_width = @input_arguments.delete(:full_width) + @full_width = @input_arguments.delete(:full_width) { true } @size = @input_arguments.delete(:size) @input_width = @input_arguments.delete(:input_width) # If scope_name_to_model is false, the name of the input for eg. `my_field` # will be `my_field` instead of the Rails default of `model[my_field]`. @@ -253,9 +255,13 @@ end end def autofocus! input_arguments[:autofocus] = true + end + + def id + @input_arguments[:id] end # :nocov: def name raise_for_abstract_method!(__method__)