File Selector & Drop Area
Description
The File Selector and File Drop Area components allow users to select files from their device. The File Selector is typically used for selecting a single file via a standard file dialog, often styled as an input field. The File Drop Area provides a drag-and-drop zone where users can drop one or multiple files.
Usage
File Selector
Use FileSelector() to create a file input. You can set a placeholder, restrict accepted file types, and handle the selection event.
File Drop Area
Use FileDropArea() to create a drop zone. You can enable multiple file selection and handle the drop event.
API reference
public sealed class FileSelector : IComponent, ICanValidate<FileSelector>A form control that lets the user pick one or more files from disk, with optional drag-and-drop support.
Properties
public File SelectedFile { get ; private set ; }Gets or sets the selected file.
public string Placeholder { get ; set ; }Gets or sets the placeholder text shown when the component is empty.
public string Error { get ; set ; }Gets or sets the validation error message displayed beneath the component.
public bool IsInvalid { get ; set ; }Gets or sets a value indicating whether the component is currently in an invalid state.
public bool IsRequired { get ; set ; }Gets or sets a value indicating whether the component is required for form submission.
public string Accepts { get ; set ; }Gets or sets the type of files accepted by this selector. See https://www.w3schools.com/tags/att_input_accept.asp for more information. Valid values are a list of extensions, like ".txt|.doc|.docx", of media type, such as "audio/*|video/*|image/*", or a combination of both
Methods
public FileSelector NoTextBox()Removes / disables the text box on the component.
public FileSelector OnFileSelected(FileSelectedHandler handler)Registers a callback invoked when the file selected event fires.
public FileSelector SetPlaceholder(string placeholder)Sets the placeholder of the component.
public FileSelector SetAccepts(string accepts)Sets the type of files accepted by this selector. See https://www.w3schools.com/tags/att_input_accept.asp for more information. Valid values are a list of extensions, like ".txt|.doc|.docx", of media type, such as "audio/*|video/*|image/*", or a combination of both
Parameters
- accepts
public void Attach(ComponentEventHandler<FileSelector> handler)Attaches a handler to the component's value-changed event.
public sealed class FileDropArea : IComponentA drop target that accepts files dragged from the operating system, with hover and validation feedback.
Constructors
Properties
public IComponent Content { set ; }Sets the content rendered inside the surface.
public string Accepts { get ; set ; }Gets or sets the type of files accepted by this selector. See https://www.w3schools.com/tags/att_input_accept.asp for more information. Valid values are a list of extensions, like ".txt|.doc|.docx", of media type, such as "audio/*|video/*|image/*", or a combination of both
Methods
public delegate void FilesDroppedHandler(FileDropArea sender, File[] files)To accept multiple files, mark the FileDropArea as multiple.
public FileDropArea OnFilesDropped(FilesDroppedHandler handler)Registers a callback invoked when the files dropped event fires.
public FileDropArea SetContent(IComponent content)Sets the content of the component.
public FileDropArea SetAccepts(string accepts)Sets the type of files accepted by this selector. See https://www.w3schools.com/tags/att_input_accept.asp for more information. Valid values are a list of extensions, like ".txt|.doc|.docx", of media type, such as "audio/*|video/*|image/*", or a combination of both
Parameters
- accepts
Samples
File Selector and Drop Area Sample
This sample demonstrates both components.