fix(a11y/attachment): associate input to label, no empty id

This commit is contained in:
Colin Darie 2022-11-24 13:45:33 +01:00
parent 1db40de70e
commit 42b84384dd
2 changed files with 3 additions and 4 deletions

View file

@ -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)

View file

@ -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?) }