refactor(simple routing): move button index in the component
This commit is contained in:
parent
304fb9ecef
commit
61c8fa4601
2 changed files with 6 additions and 8 deletions
|
@ -17,8 +17,8 @@ class Dsfr::RadioButtonListComponent < ApplicationComponent
|
||||||
end
|
end
|
||||||
|
|
||||||
def each_button
|
def each_button
|
||||||
@buttons.each do |button|
|
@buttons.each.with_index do |button, index|
|
||||||
yield(*button.values_at(:label, :value, :hint, :tooltip), **button.except(:label, :value, :hint, :tooltip))
|
yield(*button.values_at(:label, :value, :hint, :tooltip), **button.merge!(index:).except(:label, :value, :hint, :tooltip))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -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 }
|
%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
|
%legend.fr-fieldset__legend--regular.fr-fieldset__legend
|
||||||
= content
|
= content
|
||||||
- index = 0
|
|
||||||
- each_button do |label, value, hint, tooltip, **button_options|
|
- each_button do |label, value, hint, tooltip, **button_options|
|
||||||
- index += 1
|
|
||||||
.fr-fieldset__element
|
.fr-fieldset__element
|
||||||
.fr-radio-group
|
.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
|
= @form.label @target, value: value, class: 'fr-label' do
|
||||||
- capture do
|
- capture do
|
||||||
= label
|
= label
|
||||||
|
@ -16,9 +14,9 @@
|
||||||
- if hint.present?
|
- if hint.present?
|
||||||
.flex
|
.flex
|
||||||
.fr-hint-text= hint
|
.fr-hint-text= hint
|
||||||
- if tooltip.present?
|
- if tooltip.present? && button_options[:index]
|
||||||
.fr-icon-information-line.fr-icon--sm.ml-1{ 'aria-describedby': "tooltip-#{index}" }
|
.fr-icon-information-line.fr-icon--sm.ml-1{ 'aria-describedby': "tooltip-#{button_options[:index]}" }
|
||||||
%span.fr-tooltip.fr-placement{ id: "tooltip-#{index}", role: 'tooltip', 'aria-hidden': 'true' }= tooltip
|
%span.fr-tooltip.fr-placement{ id: "tooltip-#{button_options[:index]}", role: 'tooltip', 'aria-hidden': 'true' }= tooltip
|
||||||
|
|
||||||
.fr-messages-group{ 'aria-live': 'assertive' }
|
.fr-messages-group{ 'aria-live': 'assertive' }
|
||||||
- if error?
|
- if error?
|
||||||
|
|
Loading…
Reference in a new issue