File trigger
ProMakes any library button open the file picker, or the camera on phones; useFileTrigger does it from a menu item. Not an M3 component (@windmorph/react-pro).
import { FileTrigger, useFileTrigger } from '@windmorph/react-pro';Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.
Props
FileTrigger 9 props
One library button (Button, IconButton, Fab…) or anything reading
TriggerContext.A ref to the hidden
<input type="file">, e.g. to read itsfilesor reset it yourself.MIME types, wildcards (
image/*, or*for any file) or extensions the picker offers and takes, e.g.['image/jpeg', '.pdf'], in any case; an entry may hold several, separated by commas. With no list, any file is taken. A file's type comes from the system and can differ from the one you expect (a CSV isapplication/vnd.ms-excelwhere a spreadsheet app owns the extension), so list the extensions too:['text/csv', '.csv']. It checks the name and the system's type, not the content (a renamed file passes): check files on the server too. A file the system gives no type (an extension it doesn't know) matches only by extension.Lets the person choose several files.
On phones, opens the front (
user) or back (environment) camera instead of the files.Chooses a folder (and everything in it) instead of files, where the browser supports it. The files the system keeps there for itself (
.DS_Store,Thumbs.db, any dot file) are left out, neither taken nor reported.
Events
Called once for each pick from the system dialog, with every file it brought: the files taken and the files refused with their reasons, in the order they came (
acceptedis empty when every file was refused,rejectedwhen none was). Called first, thenonFileAcceptandonFileReject, all in the same task, so an app can treat a pick as one thing (add what fits, and say once what was left out). A pick that brings no files (a closed dialog) calls nothing.Called with the chosen files that match
accept; never with an empty list.Called with the chosen files that don't match
accept, each with itsreason(type), afteronFileAccept; never with an empty list.acceptis only a hint to the system dialog (a person can pick any file there, and a folder's contents ignore it), so such a file never reachesonFileAccept.
Hooks
useFileTrigger
The file picker for a trigger that can't be wrapped in FileTrigger, such as a menu item's action: open() opens it and input is the hidden input that does the work. Not an M3 component (Windmorph Pro, docs/plans/shaped-icon-skip-link-file-trigger.md).
What to accept and what to do with the chosen files.
Called once for each pick from the system dialog, with every file it brought: the files taken and the files refused with their reasons, in the order they came (
acceptedis empty when every file was refused,rejectedwhen none was). Called first, thenonFileAcceptandonFileReject, all in the same task, so an app can treat a pick as one thing (add what fits, and say once what was left out). A pick that brings no files (a closed dialog) calls nothing.Called with the chosen files that match
accept; never with an empty list.Called with the chosen files that don't match
accept, each with itsreason(type), afteronFileAccept; never with an empty list.acceptis only a hint to the system dialog (a person can pick any file there, and a folder's contents ignore it), so such a file never reachesonFileAccept.MIME types, wildcards (
image/*, or*for any file) or extensions the picker offers and takes, e.g.['image/jpeg', '.pdf'], in any case; an entry may hold several, separated by commas. With no list, any file is taken. A file's type comes from the system and can differ from the one you expect (a CSV isapplication/vnd.ms-excelwhere a spreadsheet app owns the extension), so list the extensions too:['text/csv', '.csv']. It checks the name and the system's type, not the content (a renamed file passes): check files on the server too. A file the system gives no type (an extension it doesn't know) matches only by extension.Lets the person choose several files.
On phones, opens the front (
user) or back (environment) camera instead of the files.Chooses a folder (and everything in it) instead of files, where the browser supports it. The files the system keeps there for itself (
.DS_Store,Thumbs.db, any dot file) are left out, neither taken nor reported.A ref to the hidden
<input type="file">, e.g. to read itsfilesor reset it yourself; it's merged with the hook's own ref.
Returns FileTriggerResult
Opens the file picker. Call it from a press or key handler: browsers need a user action.
The hidden file input. Render it once, anywhere near the trigger.
Spec status
Not part of Material Design 3: a Windmorph Pro component, built on M3's colour roles, type scale, shapes and motion. Its variants and configurations each link to a live example.
| Item | Status | Details |
|---|---|---|
| Any library button as the trigger | Built | Configuration · Photo |
File types (accept) | Built | Configuration · Photo, Folder |
The camera on phones (capture) | Built | Configuration · Photo |
Several files or a folder (multiple, directory) | Built | Configuration · Folder |
From a menu item (useFileTrigger) | Built | Use case · Menu |
Options
onFileAcceptgets the chosen files that matchacceptas an array, never empty. Choosing the same file again still calls it.acceptlists MIME types, wildcards or extensions, in any case. List the extensions beside the MIME types (['text/csv', '.csv']), since a file's type comes from the system and can differ from the one you expect (a CSV isapplication/vnd.ms-excelwhere a spreadsheet app owns it).*or*/*takes any file, as does no list, and an entry may hold several types, comma-separated. The system dialog only hints at it (a person can pick any file there, and a folder's contents ignore it), so a chosen file off it never reachesonFileAccept.onFileReject(rejections)gets the files a pick brought that weren't taken, afteronFileAcceptand never with an empty list, each with itsreason(type, offaccept), so you can say why a file didn't appear. Check the real type on the server too, since a file's name and type can lie.onFilePick(pick)is called once for each pick that brings files, with all of them:accepted, the files taken, andrejected, the files refused with their reasons, each list in the order the files came (acceptedis empty when every file was refused). It runs first, thenonFileAcceptandonFileReject, all in the same task, so you can treat a pick as one thing: add what fits and say once what was left out. A closed dialog calls nothing. It is enough on its own to take files, and each callback gets its own copy of the lists. Its type,FilePick, comes from@windmorph/react-pro.multipleallows several files,captureopens the front (user) or back (environment) camera on phones, anddirectorychooses a folder where the browser supports it, leaving out the files the system keeps there for itself (.DS_Store,Thumbs.db, dot files), neither taken nor reported.useFileTrigger(options)returns{ open, input }for triggers that can't be wrapped, such as a menu item: callopen()from its action and renderinputonce.