Data
TwAttachment
TwAttachment is a Blazor file attachment chip for chat surfaces, with a preview or file type icon, size, upload progress, errors, retry and remove actions.
Last updated
Please be aware this component is new, may have bugs and/or be subject to change. Please report any bugs at
https://github.com/twblazor/twblazor/issues.
Basic usage
Give
TwAttachment a FileName and a FileSize in bytes. The icon is picked from the file's extension, or from its ContentType when you pass one.quarterly-report.pdf2.3 MB · PDF
budget.xlsx47.1 KB · XLSX
notes.md1.2 KB · MD
Program.cs8.8 KB · CS
RAZOR
<div class="flex flex-wrap gap-3">
<TwAttachment FileName="quarterly-report.pdf" FileSize="2_457_600" />
<TwAttachment FileName="budget.xlsx" FileSize="48_230" />
<TwAttachment FileName="notes.md" FileSize="1_204" />
<TwAttachment FileName="Program.cs" FileSize="8_960" />
</div>Preview
Set
PreviewSrc to show a thumbnail. If it fails to load, the attachment falls back to the file type icon.logo.svg3 KB · SVG

holiday.png1 MB · PNG
RAZOR
<div class="flex flex-wrap gap-3">
<TwAttachment FileName="logo.svg" FileSize="3_120" PreviewSrc="_content/TwBlazor.Docs/images/logo.svg" />
<TwAttachment FileName="holiday.png" FileSize="1_048_576" PreviewSrc="/images/missing-picture.png" ContentType="image/png" />
</div>Upload states
Set
Status to show where the upload is. While Uploading, pass Progress from 0 to 100, or leave it unset when the progress is not known. When it Failed, an error is shown and an OnRetry callback adds a retry button.design-spec.pdf5 MB · PDF
video.mp4
Uploading video.mp4archive.zipFile is larger than 25 MB
archive.zip failed to uploadRemovable list
Set
OnRemove to add a remove button that names the file, for example in the list of files waiting to be sent with a message.brief.pdf117.2 KB · PDF
moodboard.png117.2 KB · PNG
copy-deck.docx117.2 KB · DOCX
Links and actions
Set
Href to make the file name a link once the file is ready. Use Actions for extra buttons, which sit before the built-in ones.contract.docx93.8 KB · DOCX
RAZOR
<TwAttachment FileName="contract.docx" FileSize="96_000" Href="#" OnRemove="@(() => { })">
<Actions>
<TwIcon Icon="Icon.Download" AriaLabel="Download contract.docx" OnClick="@(() => { })" />
</Actions>
</TwAttachment>Accessibility
The attachment is a group named after its file. The preview image is decoration, since the name is written beside it. The remove and retry buttons name the file they act on, and the retry button is described by the error. The upload progress bar is named "Uploading" and the file name, and starting, finishing and failing an upload are announced through a polite live region. A long file name is cut short on screen but read in full, and shown in full on hover.
Theme configuration
Styling is controlled by
TwBlazorTheme.Components (a TwAttachmentTheme), configured via the
AddTwBlazor() options callback described on the Get Started page.
Every property is a set of Tailwind classes, so changes are picked up by your own Tailwind build.
Full reference: TwAttachmentTheme on the API docs.