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-mb-0': true
}.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?
@opts.deep_merge!('aria-describedby': hint_id)
aria_describedby << hint_id
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
@opts[react ? :is_required : :required] = true
end

View file

@ -27,13 +27,13 @@ class EditableChamp::DropDownListComponent < EditableChamp::EditableChampBaseCom
end
def react_props
react_input_opts(id: @champ.input_id,
react_input_opts(
id: @champ.input_id,
class: 'fr-mt-1w',
name: @form.field_name(:value),
selected_key: @champ.selected,
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,
'aria-describedby': @champ.describedby_id,
'aria-labelledby': @champ.labelledby_id)
empty_filter_key: @champ.drop_down_other? ? Champs::DropDownListChamp::OTHER : nil
)
end
end

View file

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