From 9e5ade817a2ebf6364ac0fccecf844af234bdd1f Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Mon, 9 Oct 2023 13:02:58 +0200 Subject: [PATCH] fix(form): conditional hides fieldset__element so vertical margins are not cumulated --- .../editable_champ/editable_champ_component.rb | 9 +++++++-- .../editable_champ_component.html.haml | 13 +++++++------ .../section_component/section_component.html.haml | 6 ++---- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/components/editable_champ/editable_champ_component.rb b/app/components/editable_champ/editable_champ_component.rb index c6fb5f5e3..efe61137d 100644 --- a/app/components/editable_champ/editable_champ_component.rb +++ b/app/components/editable_champ/editable_champ_component.rb @@ -30,15 +30,20 @@ class EditableChamp::EditableChampComponent < ApplicationComponent { 'editable-champ': true, "editable-champ-#{@champ.type_champ}": true, - "hidden": !@champ.visible?, champ_component.dsfr_group_classname => true }.merge(champ_component.input_group_error_class_names) ), - id: @champ.input_group_id, data: { controller: stimulus_controller, **data_dependent_conditions, **stimulus_values } } end + def fieldset_element_attributes + { + id: @champ.input_group_id, + "hidden": !@champ.visible? + } + end + def stimulus_values if @champ.fetch_external_data_pending? { turbo_poll_url_value: } diff --git a/app/components/editable_champ/editable_champ_component/editable_champ_component.html.haml b/app/components/editable_champ/editable_champ_component/editable_champ_component.html.haml index b723dc10d..7bb16ec8f 100644 --- a/app/components/editable_champ/editable_champ_component/editable_champ_component.html.haml +++ b/app/components/editable_champ/editable_champ_component/editable_champ_component.html.haml @@ -1,9 +1,10 @@ -= content_tag((champ_component.dsfr_champ_container), html_options) do - - if has_label?(@champ) - = render EditableChamp::ChampLabelComponent.new form: @form, champ: @champ, seen_at: @seen_at +.fr-fieldset__element{ **fieldset_element_attributes } + = content_tag((champ_component.dsfr_champ_container), html_options) do + - if has_label?(@champ) + = render EditableChamp::ChampLabelComponent.new form: @form, champ: @champ, seen_at: @seen_at - = render champ_component + = render champ_component - = render Dsfr::InputStatusMessageComponent.new(errors_on_attribute: champ_component.errors_on_attribute?, error_full_messages: champ_component.error_full_messages, described_by: @champ.describedby_id) + = render Dsfr::InputStatusMessageComponent.new(errors_on_attribute: champ_component.errors_on_attribute?, error_full_messages: champ_component.error_full_messages, described_by: @champ.describedby_id) - = @form.hidden_field :id, value: @champ.id + = @form.hidden_field :id, value: @champ.id diff --git a/app/components/editable_champ/section_component/section_component.html.haml b/app/components/editable_champ/section_component/section_component.html.haml index e1c5d0550..f7a718781 100644 --- a/app/components/editable_champ/section_component/section_component.html.haml +++ b/app/components/editable_champ/section_component/section_component.html.haml @@ -8,8 +8,7 @@ = render section - else = fields_for champ.input_name, champ do |form| - .fr-fieldset__element - = render EditableChamp::EditableChampComponent.new form:, champ: + = render EditableChamp::EditableChampComponent.new form:, champ: - else %fieldset.fr-fieldset.fr-my-0 - if header_section @@ -20,5 +19,4 @@ = render section - else = fields_for champ.input_name, champ do |form| - .fr-fieldset__element - = render EditableChamp::EditableChampComponent.new form:, champ: + = render EditableChamp::EditableChampComponent.new form:, champ: