refactor(simple routing): move button index in the component

This commit is contained in:
Eric Leroy-Terquem 2024-11-14 12:03:44 +01:00
parent 304fb9ecef
commit 61c8fa4601
No known key found for this signature in database
GPG key ID: 53D8FAECEF207605
2 changed files with 6 additions and 8 deletions

View file

@ -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

View file

@ -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?