Actions
File Trigger
A visible label that asks the browser for files.
When to use it: Use it when a person must choose local files.
Example
No file selected
import { useState } from "react";
import { FileTrigger } from "@comp0/react";
export function Example() {
const [name, setName] = useState("No file selected");
return (
<div className="flex flex-col gap-2">
<FileTrigger
className="inline-flex w-fit cursor-pointer rounded border border-dashed border-zinc-950/20 px-3 py-2.5 text-base text-zinc-800 has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-teal-600 sm:py-2 sm:text-sm dark:border-white/20 dark:text-zinc-100 dark:has-focus-visible:outline-teal-400"
name="example-file"
aria-label="Choose a file"
onChange={(event) => setName(event.currentTarget.files?.[0]?.name ?? "No file selected")}
>
Choose a file
</FileTrigger>
<p className="text-base text-zinc-600 sm:text-sm dark:text-zinc-400">{name}</p>
</div>
);
}Anatomy
Dashed frames are invisible state providers; shaded shapes own real DOM. Numbered pins match the list below.
A wireframe sketch of the assembled component. Each numbered marker matches a part in the list that follows.
FileTrigger
Native label that owns the visible trigger words. Owns a DOM element.
file input
Visually hidden native file input owned by FileTrigger. Owns a DOM element.
Step by step
- 1
Add the main part
Style FileTrigger itself and give it clear words such as Upload photo.
- 2
Add the supporting parts
Pass native file props such as accept, multiple, name, and onChange directly.
- 3
Make the behavior clear
The native input stays visually hidden but focusable by default, so keyboard users can reach it.
Exampletsx <FileTrigger name="photo">Upload photo</FileTrigger>
Keyboard
- ↵
- Opens the browser file picker.
- Space
- Opens the browser file picker.
Forms and accessibility
The hidden input submits selected files using FileTrigger's name prop.
Accessibility checklist
- Name the visible trigger after the file task.
- Show accepted file types in visible help when needed.
- The input ships visually hidden but focusable; do not re-hide it with the hidden attribute.
API reference
import { FileTrigger } from "@comp0/react";FileTrigger
DOM elementNative label that owns the visible trigger words.
| Prop | Type | Description |
|---|---|---|
name | string | Native form submission name. |
accept | string | Accepted file types using native input syntax. |
multiple | boolean | Allows more than one file to be selected. |
onChange | (event: ChangeEvent) => void | Receives the native file change event. |
file input
DOM elementVisually hidden native file input owned by FileTrigger.