Use the file upload component to help users select and upload one or more files.
There are two cases in which the file upload component can be used:
When the user should only be able to select and upload one file, the file upload component can be used as is. See the “default” example.
When the user should be able to select and upload one or more files, the file upload component is placed in a fieldset.
There are two ways of using and presenting the file upload component in a fieldset to upload one or more files:
The file upload component is a form element that should always be used in a form. For a description of the usage, the behavior, the layout and validation of form elements, see the form component documentation.
<section class="file-upload multiple">
<div class="form-item">
{% include '@form-label' with {
"label": label,
"for": id ~ '--' ~ _self.name,
} %}
<div class="form-columns">
<div class="form-item-column">
{% render '@file' with {
id: id ~ '--' ~ _self.name,
name: name ~ '--' ~ _self.name|default(id ~ '--' ~ _self.name),
multiple: true
} %}
{% include '@tag-list' with {
tags: [
{text: 'my uploaded file.pdf', type: 'filter-tag'},
{text: 'another_file.pdf', type: 'filter-tag'},
{text: 'my_image.jpg', type: 'filter-tag'},
{text: 'super_secret.txt', type: 'filter-tag'}
]
} %}
</div>
<div class="form-item-column"></div>
</div>
</div>
</section>
<section class="file-upload multiple">
<div class="form-item">
<label for="file-upload--multiple">Attachments (max. 3)
</label>
<div class="form-columns">
<div class="form-item-column">
<div class="file" data-file="No file chosen">
<input type="file" id="file-upload--multiple" aria-describedby="file-upload--multiple-description" name="--multiple" multiple />
<span id="file-upload--multiple-description" class="file__button">Select your files here to upload</span>
</div>
<span class="help-text">Allowed file formats: jpg, jpeg, png and gif. Maximum file size: 2 MB. Images must be larger than 744x465 pixels.</span>
<div class="tag-list-wrapper">
<ul class="tag-list">
<li>
<span class="tag filter ">
my uploaded file.pdf
<button><span class="visually-hidden">Remove my uploaded file.pdf</span></button>
</span>
</li>
<li>
<span class="tag filter ">
another_file.pdf
<button><span class="visually-hidden">Remove another_file.pdf</span></button>
</span>
</li>
<li>
<span class="tag filter ">
my_image.jpg
<button><span class="visually-hidden">Remove my_image.jpg</span></button>
</span>
</li>
<li>
<span class="tag filter ">
super_secret.txt
<button><span class="visually-hidden">Remove super_secret.txt</span></button>
</span>
</li>
</ul>
</div>
</div>
<div class="form-item-column"></div>
</div>
</div>
</section>
{
"id": "file-upload",
"label": "Attachments (max. 3)"
}
.file-upload {
&.multiple {
.file {
&::after {
display: none;
}
}
.tag-list-wrapper {
margin-top: .25rem;
}
}
ul.inline, /// @deprecated since 4.0.0
.tag-list-wrapper {
margin-top: .8rem;
li {
margin-right: .4rem;
margin-bottom: .4rem;
}
}
.button {
margin-bottom: .8rem;
&:focus {
background-size: 100% 100%;
}
}
label {
margin-bottom: 0;
}
}