Inputs
FileInput
BitFileInput is the selection half of working with files: it lets the user hand files to the app - through the file dialog, by dragging them out of the OS onto the component, or by pasting them from the clipboard - without uploading anything anywhere. Each selected file surfaces in C# as a BitFileInputInfo carrying its name, size, MIME type, last-modified time and, on request, the pixel dimensions of an image, and its content can be pulled on demand as a byte array. Selections are validated on arrival against per-file size bounds, a total size budget, allowed extensions or MIME types, a maximum file count, a no-duplicates rule and any custom rule; files that fail stay in the list, marked invalid with a customizable message, so the user can see exactly what went wrong, and the list level limits release their files again as soon as removals free up room. The built-in file list shows names, human-readable sizes, optional image thumbnails and per-file remove buttons, and both the browse area and the list items can be replaced wholesale with templates. Accessibility is wired in rather than bolted on: the constraints can be spelled out in a description tied to the browse button through aria-describedby, and every change of the list is announced through an ARIA live region. When it is time to actually send files to a server, reach for the BitFileUpload component instead.
Usage
Every example is live. Open its code to see exactly what produced the component running underneath.
Basic
AllowDrop & AllowPaste
Description
Multiple
AutoReset
Append
AllowDuplicates
Size limits
Accept & AllowedExtensions
MaxCount
FileValidator
ReadImageDimensions
Directory
Capture
Preview
Removable
FileSizeFormatter
HideFileList
Events
Templates
Public API
Accessibility
Variant
Color
External Icons
Size
Style & Class
RTL
API
Every parameter, public member, sub-class and enum this component exposes.
BitFileInput parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| Accept | string? | null | Accepted file types for the file browser using MIME types or file extensions (e.g., "image/*", ".pdf,.doc"). Applied to the underlying HTML input element's accept attribute. When not set, the accept attribute is generated from AllowedExtensions. |
| AllowDrop | bool | true | Whether files can be selected by dragging them from the operating system and dropping them on the component. |
| AllowDuplicates | bool | true | Whether a file that is already in the file list can be selected again. When disabled, a newly selected file matching an existing one by name, size and last modified time is marked as invalid with the DuplicateErrorMessage instead of being added as a second entry, becoming valid again once the file it duplicates is removed. |
| AllowedExtensions | IReadOnlyCollection<string> | ["*"] | Allowed file types for validation purposes, accepting both file extensions (e.g., [".jpg", ".png", ".pdf"]) and MIME types with an optional wildcard (e.g., ["image/*", "application/pdf"]). The leading dot of an extension is optional and the matching is case-insensitive. Use ["*"] to allow all file types. Files not matching any of these entries will be marked as invalid. |
| AllowPaste | bool | true | Whether files can be selected by pasting them from the clipboard onto the component. The paste is only captured while the focus is inside the component, so the browse button must be focused first. |
| AnnouncementProvider | Func<IReadOnlyList<BitFileInputInfo>, string?>? | null | Custom provider of the text announced by the screen reader through the live region of the component whenever the file list changes. Receives the current file list and returns the text to announce, or null to announce nothing. When not set, a built-in English announcement is used. |
| Append | bool | false | Whether to append newly selected files to the existing file list instead of replacing it. |
| AutoReset | bool | false | Whether the file input is automatically reset (cleared) before opening the file browser dialog, allowing the same file to be selected multiple times consecutively. |
| Capture | string? | null | The capture behavior of the file input on devices with a camera or microphone, rendered as the capture attribute of the input element (e.g., "user" for the front camera, "environment" for the rear camera). |
| Classes | BitFileInputClassStyles? | null | Custom CSS classes for different parts of the BitFileInput. |
| Color | BitColor? | null | The general color of the file input, applied to the browse button and the drag-and-drop indicator. |
| Description | string? | null | A short hint rendered under the browse button and wired to it through aria-describedby, which is the place to spell out the accepted file types and the size limits so that both sighted and screen reader users learn the constraints before hitting them. |
| DescriptionTemplate | RenderFragment? | null | Custom Razor template of the hint rendered under the browse button, taking precedence over Description. |
| Directory | bool | false | Whether to select folders (directories) instead of files, rendered as the webkitdirectory attribute. All files inside the selected folder and its subfolders will be added to the file list. It also makes a dropped folder expand into its contents instead of being ignored. |
| DuplicateErrorMessage | string? | null | Custom error message displayed when a file is selected again while AllowDuplicates is disabled. Defaults to "The file is already selected". |
| FileValidator | Func<BitFileInputInfo, string?>? | null | Custom validation function called for each newly selected file after the built-in validations pass. Return an error message to mark the file as invalid, or null to accept it. |
| FileSizeFormatter | Func<long, string>? | null | Custom formatter of the file size shown under the name of each file item. Receives the size of the file in bytes and returns the text to display, which is the place to localize the units or to switch between the binary and the decimal bases. When not set, a built-in humanizer is used. |
| FileViewTemplate | RenderFragment<BitFileInputInfo>? | null | Custom Razor template for rendering individual file items in the file list. Receives a BitFileInputInfo context for each file. |
| HideFileList | bool | false | Whether to hide the file list that displays the selected files in the UI. |
| HideLabel | bool | false | Whether to hide the default browse button label from the UI. |
| Label | string | Browse | The text displayed on the browse button. Defaults to "Browse". |
| LabelTemplate | RenderFragment? | null | Custom Razor template for the browse button area, allowing full customization of the file selection trigger UI. |
| MaxCount | int | 0 | Maximum allowed number of files in the file list. Files selected beyond this count will be marked as invalid, becoming valid again once removals free up room. Set to 0 for no count limit. |
| MaxCountErrorMessage | string? | null | Custom error message displayed when the number of files exceeds the maximum count limit. Defaults to "The maximum number of files is exceeded". |
| MaxSize | long | 0 | Maximum allowed file size in bytes for validation. Files exceeding this size will be marked as invalid. Set to 0 for no size limit. |
| MaxSizeErrorMessage | string? | null | Custom error message displayed when a file exceeds the maximum size limit. Defaults to "The file size is larger than the max size". |
| MaxTotalSize | long | 0 | Maximum allowed total size in bytes of all the files in the file list. Files pushing the accumulated size beyond this limit will be marked as invalid, becoming valid again once removals free up room. Set to 0 for no total size limit. |
| MaxTotalSizeErrorMessage | string? | null | Custom error message displayed when a file makes the total size of the file list exceed the maximum total size. Defaults to "The total size of the files is larger than the max total size". |
| MinSize | long | 0 | Minimum allowed file size in bytes for validation. Files smaller than this size will be marked as invalid. Set to 0 for no size limit. |
| MinSizeErrorMessage | string? | null | Custom error message displayed when a file is smaller than the minimum size limit. Defaults to "The file size is smaller than the min size". |
| Multiple | bool | false | Whether to allow selecting multiple files simultaneously through the file browser dialog. |
| NotAllowedExtensionErrorMessage | string? | null | Custom error message displayed when a file's extension is not in the allowed extensions list. Defaults to "The file type is not allowed". |
| OnChange | EventCallback<BitFileInputInfo[]> | Callback invoked when the file selection changes, providing an array of BitFileInputInfo representing all selected files. It is also invoked after removing a file through the remove button or the RemoveFile method. | |
| OnInvalid | EventCallback<BitFileInputInfo[]> | Callback invoked right after OnChange whenever the file list holds at least one invalid file, providing an array of only the invalid files along with their validation messages. | |
| OnRemove | EventCallback<BitFileInputInfo> | Callback invoked for each file that gets removed from the file list, either through the remove button or the RemoveFile method. | |
| ReadImageDimensions | bool | false | Whether to decode every selected image file to fill the Width and Height properties of its file info with the pixel dimensions, which makes it possible to enforce resolution rules from a FileValidator. Decoding costs time and memory proportional to the images, so it is disabled by default. |
| RemoveButtonIcon | BitIconInfo? | null | Gets or sets the remove button icon using custom CSS classes for external icon libraries. Takes precedence over RemoveButtonIconName when both are set. |
| RemoveButtonIconName | string? | Delete | Gets or sets the name of the remove button icon from the built-in Fluent UI icons. |
| RemoveButtonTitle | string? | null | The tooltip of the remove button, which is also used as the prefix of its accessible label (e.g., "Remove report.pdf"). Defaults to "Remove". |
| ShowPreview | bool | false | Whether to display a preview thumbnail for image files in the file list. |
| ShowRemoveButton | bool | false | Whether to display a remove button next to each file in the file list, allowing individual file removal. |
| Size | BitSize? | null | The size of the file input, applied to the browse button and the file list items. |
| Styles | BitFileInputClassStyles? | null | Custom CSS styles for different parts of the BitFileInput. |
| Variant | BitVariant? | null | The visual variant of the browse button, which decides how much of the Color it carries: a full fill, only an outline, or neither. |
BitFileInput public members
| Name | Type | Default value | Description |
|---|---|---|---|
| Files | IReadOnlyList<BitFileInputInfo> | [] | A read-only list of all currently selected files with their metadata, validation status, and content. |
| InputId | string? | The unique identifier of the underlying HTML file input element. | |
| Browse | () => Task | Opens the file browser dialog programmatically, allowing users to select files. If AutoReset is enabled, the input is reset before opening. | |
| ReadContentAsync | (BitFileInputInfo? fileInfo = null) => Task | Reads the content of the specified file from the browser and populates its Content property with the byte array, or reads every valid file of the file list when no file is specified. Only reads valid files and only while the component is enabled. | |
| RemoveFile | (BitFileInputInfo? fileInfo = null) => Task | Removes a specific file from the selected files list, or clears all files when no file is specified, invoking the OnRemove callback for each removed file and the OnChange callback afterwards. | |
| Reset | () => Task | Clears all selected files and resets the file input to its initial state without invoking any callback. |
BitComponentBase parameters
| Name | Type | Default value | Description |
|---|---|---|---|
| AriaLabel | string? | null | Gets or sets the accessible label for the component, used by assistive technologies. |
| Class | string? | null | Gets or sets the CSS class name(s) to apply to the rendered element. |
| Dir | BitDir? | null | Gets or sets the text directionality for the component's content. |
| ForceAnimation | bool | false | Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested. |
| HtmlAttributes | Dictionary<string, object> | new Dictionary<string, object>() | Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. |
| Id | string? | null | Gets or sets the unique identifier for the component's root element. |
| IsEnabled | bool | true | Gets or sets a value indicating whether the component is enabled and can respond to user interaction. |
| Style | string? | null | Gets or sets the CSS style string to apply to the rendered element. |
| TabIndex | string? | null | Gets or sets the tab order index for the component when navigating with the keyboard. |
| Visibility | BitVisibility | BitVisibility.Visible | Gets or sets the visibility state (visible, hidden, or collapsed) of the component. |
BitComponentBase public members
| Name | Type | Default value | Description |
|---|---|---|---|
| UniqueId | Guid | Guid.NewGuid() | Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed. |
| RootElement | ElementReference | Gets the reference to the root HTML element associated with this component. |
BitFileInputInfo properties
Represents metadata, validation state, and content of a file selected through BitFileInput.
| Name | Type | Default value | Description |
|---|---|---|---|
| ContentType | string | string.Empty | The MIME content type of the file (e.g., "image/png", "application/pdf"). |
| Name | string | string.Empty | The name of the file including its extension (e.g., "document.pdf"). |
| Size | long | The size of the file in bytes. | |
| FileId | string | string.Empty | A unique identifier (GUID) assigned to the file upon selection, used to reference the file in JavaScript interop. |
| Index | int | The zero-based index of the file in the current selection list. | |
| LastModified | long | The last modified time of the file reported by the browser, in milliseconds since the Unix epoch. | |
| LastModifiedDate | DateTimeOffset | The last modified time of the file reported by the browser, as a DateTimeOffset. | |
| PreviewUrl | string? | null | An object URL of the file content that can be used as the source of an img element to preview image files. This is only populated for image files when the ShowPreview parameter of the BitFileInput is enabled. |
| Width | int? | null | The width of the image in pixels, only populated for decodable image files when the ReadImageDimensions parameter of the BitFileInput is enabled. It is null for anything else. |
| Height | int? | null | The height of the image in pixels, only populated for decodable image files when the ReadImageDimensions parameter of the BitFileInput is enabled. It is null for anything else. |
| IsValid | bool | true | Whether the file has passed all validation checks including size constraints and allowed extensions. |
| Message | string? | null | The validation error message when the file has failed a validation check (e.g., size or extension). This is null when the file is valid. |
| Content | byte[]? | null | The file content as a byte array, populated by calling ReadContentAsync. This is null by default and only loaded on demand. |
BitFileInputClassStyles properties
| Name | Type | Default value | Description |
|---|---|---|---|
| Root | string? | null | Custom CSS classes/styles for the root element of the BitFileInput. |
| Dragging | string? | null | Custom CSS classes/styles for the root element while files are being dragged over the BitFileInput. |
| Label | string? | null | Custom CSS classes/styles for the browse button (label) of the BitFileInput. |
| Description | string? | null | Custom CSS classes/styles for the description (hint) of the BitFileInput. |
| FileList | string? | null | Custom CSS classes/styles for the file list container of the BitFileInput. |
| FileItem | string? | null | Custom CSS classes/styles for each file item of the BitFileInput. |
| Preview | string? | null | Custom CSS classes/styles for the image preview thumbnail of each file item of the BitFileInput. |
| FileName | string? | null | Custom CSS classes/styles for the file name of each file item of the BitFileInput. |
| FileSize | string? | null | Custom CSS classes/styles for the file size of each file item of the BitFileInput. |
| ErrorMessage | string? | null | Custom CSS classes/styles for the validation error message of each invalid file item of the BitFileInput. |
| RemoveButton | string? | null | Custom CSS classes/styles for the remove button of each file item of the BitFileInput. |
| RemoveIcon | string? | null | Custom CSS classes/styles for the remove button icon of each file item of the BitFileInput. |
BitIconInfo properties
| Name | Type | Default value | Description |
|---|---|---|---|
| Name | string? | null | Gets or sets the name of the icon. |
| BaseClass | string? | null | Gets or sets the base CSS class for the icon. For built-in Fluent UI icons, this defaults to "bit-icon". For external icon libraries like FontAwesome, you might set this to "fa" or leave empty. |
| Prefix | string? | null | Gets or sets the CSS class prefix used before the icon name. For built-in Fluent UI icons, this defaults to "bit-icon--". For external icon libraries, you might set this to "fa-" or leave empty. |
BitColor enum
| Name | Value | Description |
|---|---|---|
| Primary | 0 | Primary general color. |
| Secondary | 1 | Secondary general color. |
| Tertiary | 2 | Tertiary general color. |
| Info | 3 | Info general color. |
| Success | 4 | Success general color. |
| Warning | 5 | Warning general color. |
| SevereWarning | 6 | SevereWarning general color. |
| Error | 7 | Error general color. |
| PrimaryBackground | 8 | Primary background color. |
| SecondaryBackground | 9 | Secondary background color. |
| TertiaryBackground | 10 | Tertiary background color. |
| PrimaryForeground | 11 | Primary foreground color. |
| SecondaryForeground | 12 | Secondary foreground color. |
| TertiaryForeground | 13 | Tertiary foreground color. |
| PrimaryBorder | 14 | Primary border color. |
| SecondaryBorder | 15 | Secondary border color. |
| TertiaryBorder | 16 | Tertiary border color. |
BitSize enum
| Name | Value | Description |
|---|---|---|
| Small | 0 | The small size file input. |
| Medium | 1 | The medium size file input. |
| Large | 2 | The large size file input. |
BitVariant enum
| Name | Value | Description |
|---|---|---|
| Fill | 0 | Fill styled variant. |
| Outline | 1 | Outline styled variant. |
| Text | 2 | Text styled variant. |
BitVisibility enum
| Name | Value | Description |
|---|---|---|
| Visible | 0 | The content of the component is visible. |
| Hidden | 1 | The content of the component is hidden, but the space it takes on the page remains (visibility:hidden). |
| Collapsed | 2 | The component is hidden (display:none). |
BitDir enum
| Name | Value | Description |
|---|---|---|
| Ltr | 0 | Ltr (left to right) is to be used for languages that are written from the left to the right (like English). |
| Rtl | 1 | Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic). |
| Auto | 2 | Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element. |
Feedback
Found a mistake, a gap, or something that could be clearer? Every page and every component is one click from its source.