Skip to content

File trigger

Pro

Makes 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.

Keyboard

File trigger keyboard
KeyAction
TabMoves focus to the button inside it, and on to the next element.
Enter or SpacePresses the button, which opens the system file picker (or the phone's camera with capture).

The file picker is the browser's own dialog, so its keys are the operating system's.

Screen reader

Role
Whatever the button inside it is: usually a button.
Accessible name
The button's own name: its label, or the aria-label of an IconButton.
States announced
The button's own states, such as disabled.

The file input is hidden from everyone (hidden, aria-hidden and tabIndex={-1}), so the control is announced once, as the button.

Focus

Focus stays on the button, which shows its own focus indicator. The hidden input is never focused.

Touch target

The button is the target, at its own size: see the button you put inside it (Button, IconButton, Fab).

Motion

None. It adds no motion: the button inside it keeps its own.

What you need to do

  • Put exactly one library button inside it (or anything reading TriggerContext), with a name that says what it picks: "Change photo", not "Browse".
  • Put it inside a TooltipTrigger, not around one: the tooltip keeps working. To stop it, disable the button.
  • For a trigger it can't wrap, such as a menu item, use useFileTrigger: call open() from the item's action and render input once.
  • It announces nothing when it refuses a chosen file off accept: handle onFilePick (or onFileReject) and say why in words a screen reader hears too, such as a snackbar, once for the whole pick.