From 42b84384ddce12ef9dec9362665de35baf287e4b Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Thu, 24 Nov 2022 13:45:33 +0100 Subject: [PATCH] fix(a11y/attachment): associate input to label, no empty id --- app/components/attachment/edit_component.rb | 5 ++--- .../attachment/edit_component/edit_component.html.haml | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/components/attachment/edit_component.rb b/app/components/attachment/edit_component.rb index 15069dc48..6450a94be 100644 --- a/app/components/attachment/edit_component.rb +++ b/app/components/attachment/edit_component.rb @@ -132,9 +132,8 @@ class Attachment::EditComponent < ApplicationComponent def input_id if champ.present? - # Single or first attachment input must match label "for" attribute. Others must remain unique. - return champ.input_id if @index.zero? - return "#{champ.input_id}_#{attachment_id}" + # There is always a single input by champ, its id must match the label "for" attribute. + return champ.input_id end helpers.field_id(@attached_file.record, attribute_name) diff --git a/app/components/attachment/edit_component/edit_component.html.haml b/app/components/attachment/edit_component/edit_component.html.haml index 5b810d57a..16671296b 100644 --- a/app/components/attachment/edit_component/edit_component.html.haml +++ b/app/components/attachment/edit_component/edit_component.html.haml @@ -1,4 +1,4 @@ -.attachment.fr-upload-group{ id: attachment ? dom_id(attachment, :edit) : nil, class: class_names("fr-mb-2w": !(as_multiple? && downloadable?)) } +.attachment.fr-upload-group{ { id: attachment ? dom_id(attachment, :edit) : nil, class: class_names("fr-mb-2w": !(as_multiple? && downloadable?)) }.compact } - if persisted? %div{ id: dom_id(attachment, :persisted_row) } .flex.flex-gap-2{ class: class_names("attachment-error": attachment.virus_scanner_error?) }