From 61c8fa4601399f8a49684a9f4409174fd2d1ba68 Mon Sep 17 00:00:00 2001 From: Eric Leroy-Terquem Date: Thu, 14 Nov 2024 12:03:44 +0100 Subject: [PATCH] refactor(simple routing): move button index in the component --- app/components/dsfr/radio_button_list_component.rb | 4 ++-- .../radio_button_list_component.html.haml | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/components/dsfr/radio_button_list_component.rb b/app/components/dsfr/radio_button_list_component.rb index 775b70784..df84138a3 100644 --- a/app/components/dsfr/radio_button_list_component.rb +++ b/app/components/dsfr/radio_button_list_component.rb @@ -17,8 +17,8 @@ class Dsfr::RadioButtonListComponent < ApplicationComponent end def each_button - @buttons.each do |button| - yield(*button.values_at(:label, :value, :hint, :tooltip), **button.except(:label, :value, :hint, :tooltip)) + @buttons.each.with_index do |button, index| + yield(*button.values_at(:label, :value, :hint, :tooltip), **button.merge!(index:).except(:label, :value, :hint, :tooltip)) end end end diff --git a/app/components/dsfr/radio_button_list_component/radio_button_list_component.html.haml b/app/components/dsfr/radio_button_list_component/radio_button_list_component.html.haml index f0dd1c403..8c58448ad 100644 --- a/app/components/dsfr/radio_button_list_component/radio_button_list_component.html.haml +++ b/app/components/dsfr/radio_button_list_component/radio_button_list_component.html.haml @@ -1,12 +1,10 @@ %fieldset{ class: class_names("fr-fieldset": true, "fr-fieldset--error": error?), 'aria-labelledby': 'radio-hint-element-legend radio-hint-element-messages', role: error? ? :group : nil } %legend.fr-fieldset__legend--regular.fr-fieldset__legend = content - - index = 0 - each_button do |label, value, hint, tooltip, **button_options| - - index += 1 .fr-fieldset__element .fr-radio-group - = @form.radio_button @target, value, **button_options + = @form.radio_button @target, value, **button_options.except(:index) = @form.label @target, value: value, class: 'fr-label' do - capture do = label @@ -16,9 +14,9 @@ - if hint.present? .flex .fr-hint-text= hint - - if tooltip.present? - .fr-icon-information-line.fr-icon--sm.ml-1{ 'aria-describedby': "tooltip-#{index}" } - %span.fr-tooltip.fr-placement{ id: "tooltip-#{index}", role: 'tooltip', 'aria-hidden': 'true' }= tooltip + - if tooltip.present? && button_options[:index] + .fr-icon-information-line.fr-icon--sm.ml-1{ 'aria-describedby': "tooltip-#{button_options[:index]}" } + %span.fr-tooltip.fr-placement{ id: "tooltip-#{button_options[:index]}", role: 'tooltip', 'aria-hidden': 'true' }= tooltip .fr-messages-group{ 'aria-live': 'assertive' } - if error?