Table of Contents

Class TwAttachment

Namespace
TwBlazor.Components
Assembly
TwBlazor.dll

Represents a file attached to a message: its preview or type icon, its name, its size or upload progress, and buttons to retry or remove it.

public class TwAttachment : TwBlazorComponentBase, IComponent, IHandleEvent, IHandleAfterRender, ITwComponent
Inheritance
TwAttachment
Implements
Inherited Members

Remarks

The attachment shows PreviewSrc when it is set and loads, otherwise an icon for the file's type. Under the name it shows the size and type when the file is Ready, a progress bar while it is Uploading, and an error when the upload Failed.

Accessibility: the attachment is a group named after the file. Its remove and retry buttons name the file they act on, and the retry button is described by the error. Starting, finishing and failing an upload are announced through a polite live region. The preview is decoration, because the file name is written beside it.

Constructors

TwAttachment()

public TwAttachment()

Properties

Actions

Gets or sets extra actions shown before the retry and remove buttons.

[Parameter]
public RenderFragment? Actions { get; set; }

Property Value

RenderFragment

ContentType

Gets or sets the file's media type, for example image/png. It picks the icon shown when there is no preview.

[Parameter]
public string? ContentType { get; set; }

Property Value

string

Disabled

Gets or sets whether the retry and remove buttons are disabled.

[Parameter]
public bool Disabled { get; set; }

Property Value

bool

ErrorText

Gets or sets the error shown when the upload failed.

[Parameter]
public string? ErrorText { get; set; }

Property Value

string

Remarks

If not set, a localized "{file} failed to upload" message is shown.

FileName

Gets or sets the name of the file, for example report.pdf.

[Parameter]
[EditorRequired]
public string FileName { get; set; }

Property Value

string

FileSize

Gets or sets the size of the file in bytes. It is shown when the file is ready.

[Parameter]
public long? FileSize { get; set; }

Property Value

long?

Href

Gets or sets the URL the file name links to, for opening or downloading the file. It is only a link once the file is ready.

[Parameter]
public string? Href { get; set; }

Property Value

string

Icon

Gets or sets the icon shown when there is no preview.

[Parameter]
public Icon? Icon { get; set; }

Property Value

Icon?

Remarks

If not set, an icon is picked from ContentType or the extension of FileName.

OnRemove

Gets or sets the callback invoked by the remove button. The button is shown only when this is set.

[Parameter]
public EventCallback OnRemove { get; set; }

Property Value

EventCallback

OnRetry

Gets or sets the callback invoked by the retry button. The button is shown only when this is set and the upload failed.

[Parameter]
public EventCallback OnRetry { get; set; }

Property Value

EventCallback

PreviewSrc

Gets or sets the URL of a thumbnail of the file, such as the image itself.

[Parameter]
public string? PreviewSrc { get; set; }

Property Value

string

Progress

Gets or sets how much of the upload is done, from 0 to 100.

[Parameter]
public double? Progress { get; set; }

Property Value

double?

Remarks

Leave it unset while Uploading when the progress is not known, and the bar shows that the upload is busy.

Status

Gets or sets where the file is in its upload.

[Parameter]
public AttachmentStatus Status { get; set; }

Property Value

AttachmentStatus

Target

Gets or sets where the link opens. A _blank target adds rel="noopener".

[Parameter]
public string? Target { get; set; }

Property Value

string

Methods

BuildRenderTree(RenderTreeBuilder)

Renders the component to the supplied RenderTreeBuilder.

protected override void BuildRenderTree(RenderTreeBuilder __builder)

Parameters

__builder RenderTreeBuilder

OnParametersSet()

Invoked when the component's parameters have been set. Ensures that the component has a unique identifier by generating one if none is provided.

protected override void OnParametersSet()

Remarks

If the component's identifier is not set, a unique ID is generated based on the component's type name (with a 'Tw' prefix removed if present) and a GUID. This helps ensure that each component instance can be uniquely identified, which is useful for scenarios such as associating labels with form elements or targeting elements in client-side scripts.