From b0df654346a4cc490439189215143923b2fddabe Mon Sep 17 00:00:00 2001 From: Lisa Durand Date: Tue, 11 Apr 2023 16:32:57 +0200 Subject: [PATCH] add heading level customization to callout component to fix a11y issue --- app/components/dsfr/callout_component.rb | 5 +++-- .../dsfr/callout_component/callout_component.html.haml | 3 ++- app/views/users/dossiers/index.html.haml | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/components/dsfr/callout_component.rb b/app/components/dsfr/callout_component.rb index a84a67c03..cd69b9f56 100644 --- a/app/components/dsfr/callout_component.rb +++ b/app/components/dsfr/callout_component.rb @@ -4,13 +4,14 @@ class Dsfr::CalloutComponent < ApplicationComponent renders_one :html_body renders_one :bottom - attr_reader :title, :theme, :icon, :extra_class_names + attr_reader :title, :theme, :icon, :extra_class_names, :heading_level - def initialize(title:, theme: :info, icon: nil, extra_class_names: nil) + def initialize(title:, theme: :info, icon: nil, extra_class_names: nil, heading_level: 'h3') @title = title @theme = theme @icon = icon @extra_class_names = extra_class_names + @heading_level = heading_level end def callout_class diff --git a/app/components/dsfr/callout_component/callout_component.html.haml b/app/components/dsfr/callout_component/callout_component.html.haml index 8cb47f83a..7fd9697c3 100644 --- a/app/components/dsfr/callout_component/callout_component.html.haml +++ b/app/components/dsfr/callout_component/callout_component.html.haml @@ -1,6 +1,7 @@ %div{ class: callout_class } - if title.present? - %h3.fr-callout__title= title + = content_tag(heading_level, class: 'fr-callout__title') do + = title - if html_body? .fr-callout__text= html_body - if body? diff --git a/app/views/users/dossiers/index.html.haml b/app/views/users/dossiers/index.html.haml index 44d0e4deb..33a28ff77 100644 --- a/app/views/users/dossiers/index.html.haml +++ b/app/views/users/dossiers/index.html.haml @@ -16,7 +16,7 @@ %h1.page-title.fr-h2= t('views.users.dossiers.index.dossiers') - if @last_dossier_editable.present? - = render Dsfr::CalloutComponent.new(title: t('users.dossiers.header.callout.last_dossier_editable_title')) do |c| + = render Dsfr::CalloutComponent.new(title: t('users.dossiers.header.callout.last_dossier_editable_title'), heading_level: 'h2') do |c| - c.with_body do %p = t('users.dossiers.header.callout.last_dossier_editable_text', time_ago: time_ago_in_words(@last_dossier_editable.created_at), libelle: @last_dossier_editable.procedure.libelle )