Skip to content

Commit

Permalink
refactor(simple routing): move button index in the component
Browse files Browse the repository at this point in the history
  • Loading branch information
E-L-T committed Nov 15, 2024
1 parent 304fb9e commit 61c8fa4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/components/dsfr/radio_button_list_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def error?
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
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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?
Expand Down

0 comments on commit 61c8fa4

Please sign in to comment.