handle aria_describedby on react combobox

This commit is contained in:
simon lehericey 2024-11-27 18:02:45 +01:00 committed by Corinne Durrmeyer
parent 2e050e2f18
commit 8a0d70ee70
No known key found for this signature in database
GPG key ID: DDC049DDA35585B6
3 changed files with 18 additions and 12 deletions

View file

@ -79,12 +79,19 @@ module Dsfr
'fr-input': !react, 'fr-input': !react,
'fr-mb-0': true 'fr-mb-0': true
}.merge(input_error_class_names))) }.merge(input_error_class_names)))
if errors_on_attribute?
@opts.deep_merge!('aria-describedby': describedby_id) aria_describedby = []
if object.respond_to?(:description) && object.description.present?
aria_describedby << describedby_id
elsif hintable? elsif hintable?
@opts.deep_merge!('aria-describedby': hint_id) aria_describedby << hint_id
end end
aria_describedby << object.error_id if errors_on_attribute? && object.respond_to?(:error_id)
@opts.deep_merge!('aria-describedby': aria_describedby.join(' ')) if aria_describedby.present?
if @required if @required
@opts[react ? :is_required : :required] = true @opts[react ? :is_required : :required] = true
end end

View file

@ -27,13 +27,13 @@ class EditableChamp::DropDownListComponent < EditableChamp::EditableChampBaseCom
end end
def react_props def react_props
react_input_opts(id: @champ.input_id, react_input_opts(
id: @champ.input_id,
class: 'fr-mt-1w', class: 'fr-mt-1w',
name: @form.field_name(:value), name: @form.field_name(:value),
selected_key: @champ.selected, selected_key: @champ.selected,
items: @champ.drop_down_options_with_other.map { _1.is_a?(Array) ? _1 : [_1, _1] }, items: @champ.drop_down_options_with_other.map { _1.is_a?(Array) ? _1 : [_1, _1] },
empty_filter_key: @champ.drop_down_other? ? Champs::DropDownListChamp::OTHER : nil, empty_filter_key: @champ.drop_down_other? ? Champs::DropDownListChamp::OTHER : nil
'aria-describedby': @champ.describedby_id, )
'aria-labelledby': @champ.labelledby_id)
end end
end end

View file

@ -12,14 +12,13 @@ class EditableChamp::MultipleDropDownListComponent < EditableChamp::EditableCham
end end
def react_props def react_props
react_input_opts(id: @champ.input_id, react_input_opts(
id: @champ.input_id,
class: 'fr-mt-1w', class: 'fr-mt-1w',
name: @form.field_name(:value, multiple: true), name: @form.field_name(:value, multiple: true),
selected_keys: @champ.selected_options, selected_keys: @champ.selected_options,
items: @champ.drop_down_options, items: @champ.drop_down_options,
value_separator: false, value_separator: false
'aria-label': @champ.libelle, )
'aria-describedby': @champ.describedby_id,
'aria-labelledby': @champ.labelledby_id)
end end
end end