FileTrigger
Accessible file-input trigger styled through the button system.
Preview
A live, theme-aware example rendered with the published component.
Loading preview…
Import
Import from the focused entry point below, or use the same named export from @tavojs/ui. Both are public APIs; measure the built application when comparing their bundle cost.
tsximport { FileTrigger } from "@tavojs/ui/file-trigger";The component import loads compiled component CSS. Enable tavoUi() for your project theme variables, or import @tavojs/ui/theme.css once for the package default theme. The equivalent CSS-safe component alias is @tavojs/ui/css/file-trigger.
When to use
Use it when
Choose something else when
Examples
These examples include imports and local state where interaction requires it. Render the exported component in a page after completing UI installation. Demo state stays in the mounted component; connect file handling, persistence, and data loading to your application as needed.
FileTrigger example
tsximport { createTavo } from "@tavojs/core";
import { FileTrigger } from "@tavojs/ui/file-trigger";
import { Text } from "@tavojs/ui";
type State = { filename: string };
export const FileTriggerExample1 = createTavo<Record<string, never>, State>({
model: () => ({ filename: "No file selected" }),
view: ({ state, model }) => (
<>
<FileTrigger
accept="application/json,.json"
onFilesChange={(files) => model.set("filename", files[0]?.name ?? "No file selected")}
>
Choose JSON file
</FileTrigger>
<Text role="status">{state.filename}</Text>
</>
)
});Common props and defaults
A curated starting point. The complete TypeScript API below includes additional props and compound member contracts.
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | — | Optional class hook applied to the public root element owned by the component. |
accept | string | — | Native accepted file types. |
multiple | boolean | — | Allows more than one selected file. |
capture | boolean | "user" | "environment" | string | — | Forwards the native capture hint. |
name | string | — | Native form field name. |
resetAfterSelection | boolean | — | Clears the native value so the same file can be selected again. |
onFilesChange | (files: FileList, event) => void | — | Exposes selected native files without reading or uploading them. |
variant | ButtonVariant | — | Reuses Button styling. |
size | Size | — | Reuses Button sizing. |
Complete TypeScript API
Import from @tavojs/ui/file-trigger. Published exports: FileTrigger, FileTriggerProps.
FileTriggerProps
| Property | Type | Required | Description |
|---|---|---|---|
children | Child | No | Inherited children attribute accepted by FileTrigger. |
accept | string | No | Native accepted file types. |
multiple | boolean | No | Allows more than one selected file. |
capture | string | boolean | No | Forwards the native capture hint. |
name | string | No | Native form field name. |
resetAfterSelection | boolean | No | Clears the native value so the same file can be selected again. |
disabled | boolean | No | Inherited disabled attribute accepted by FileTrigger. |
onClick | TavoEventHandler<MouseEvent> | No | Inherited onClick attribute accepted by FileTrigger. |
onFilesChange | (files: FileList, event: Event & { currentTarget: HTMLInputElement; }) => void | No | Exposes selected native files without reading or uploading them. |
State ownership and DOM target
| Concern | Contract |
|---|---|
| State | No component state contract is exposed; the application owns the rendered content and surrounding behavior. |
| DOM target | Native input attributes target the owned form control; wrapper-specific props stay on the documented component root. |
Anatomy and related components
This component exposes one public component root rather than a compound member API.
Limitations
Avoid FileTrigger when wrapping controls without labels or accessible names.
Use only the documented props, entry points, and compound members. Internal DOM nesting and CSS class names can change without becoming part of the public component contract.
Accessibility
The visible trigger is a native button and works with pointer, Enter, and Space activation. The file input remains native and is reset only after the callback runs.
The visible trigger is a native button and works with pointer, Enter, and Space activation. The file input remains native and is reset only after the callback runs.
Component status
| Contract | Current value |
|---|---|
| Maturity | stable |
| Category | forms |
| Component import | @tavojs/ui/file-trigger |
| Explicit CSS import | @tavojs/ui/css/file-trigger |
| Preview | Interactive preview available on this page |