From 8a0d70ee706dcb01ef34415d9a90860e652714d1 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Wed, 27 Nov 2024 18:02:45 +0100 Subject: [PATCH] handle aria_describedby on react combobox --- app/components/dsfr/input_errorable.rb | 13 ++++++++++--- .../editable_champ/drop_down_list_component.rb | 8 ++++---- .../multiple_drop_down_list_component.rb | 9 ++++----- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/components/dsfr/input_errorable.rb b/app/components/dsfr/input_errorable.rb index 3648d2442..d2af06297 100644 --- a/app/components/dsfr/input_errorable.rb +++ b/app/components/dsfr/input_errorable.rb @@ -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 diff --git a/app/components/editable_champ/drop_down_list_component.rb b/app/components/editable_champ/drop_down_list_component.rb index 8d1ac7204..567a0308a 100644 --- a/app/components/editable_champ/drop_down_list_component.rb +++ b/app/components/editable_champ/drop_down_list_component.rb @@ -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 diff --git a/app/components/editable_champ/multiple_drop_down_list_component.rb b/app/components/editable_champ/multiple_drop_down_list_component.rb index aec59c019..d79b6b6eb 100644 --- a/app/components/editable_champ/multiple_drop_down_list_component.rb +++ b/app/components/editable_champ/multiple_drop_down_list_component.rb @@ -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