- Components
- Buttons
- File Trigger
File Trigger
Allows a user to access the file system with any pressable aria component.
Installation
Usage
A FileTrigger
wraps around a pressable child such as a button, and includes a visually hidden input element that allows the user to select files from their device.
Options
Accepted file types
By default, the file trigger will accept any file type. To support only certain file types, pass an array of the mime type of files via the acceptedFileTypes
prop.
Multiple files
A file trigger can accept multiple files by passsing the allowsMultiple
prop.
Directory selection
To enable selecting directories instead of files, use the acceptDirectory
property.
This reflects the webkitdirectory HTML attribute and allows users to select directories and their contents. Please note that support for this feature varies from browser to browser.
Media capture
To specify the media capture mechanism to capture media on the spot, pass user for the user-facing camera or environment for the outward-facing camera via the defaultCamera prop.
This behavior only works on mobile devices. On desktop devices, it will open the file system like normal. Read more about capture.
API Reference
Prop | Type | Description |
---|---|---|
children | ReactNode | The children of the component. |
acceptedFileTypes | Array<string> | Specifies what mime type of files are allowed. |
allowsMultiple | boolean | Whether multiple files can be selected. |
defaultCamera | 'user' | 'environment' | Specifies the use of a media capture mechanism to capture the media on the spot. |
acceptDirectory | boolean | Enables the selection of directories instead of individual files. |
Event | Type | Description |
---|---|---|
onSelect | (files: FileList | null) => void | Handler when a user selects a file. |
Accessibility
Keyboard interactions
Key | Description |
---|---|
Space Enter | Activates the trigger. |
Last updated on 10/11/2024