Navigated to /docs/ui/components/file-trigger

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.

TSX
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

Use `FileTrigger` when a native file picker should use the same visual and interaction contract as `Button`

Choose something else when

Avoid FileTrigger when wrapping controls without labels or accessible names.

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

TSXCreate: src/components/examples/FileTriggerExample1.tsx
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.

PropTypeDefaultDescription
classNamestring

Optional class hook applied to the public root element owned by the component.
acceptstring

Native accepted file types.
multipleboolean

Allows more than one selected file.
captureboolean | "user" | "environment" | string

Forwards the native capture hint.
namestring

Native form field name.
resetAfterSelectionboolean

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

Reuses Button styling.
sizeSize

Reuses Button sizing.

Complete TypeScript API

Import from @tavojs/ui/file-trigger. Published exports: FileTrigger, FileTriggerProps.

FileTriggerProps

PropertyTypeRequiredDescription
childrenChild

No

Inherited children attribute accepted by FileTrigger.

acceptstring

No

Native accepted file types.

multipleboolean

No

Allows more than one selected file.

capturestring | boolean

No

Forwards the native capture hint.

namestring

No

Native form field name.

resetAfterSelectionboolean

No

Clears the native value so the same file can be selected again.

disabledboolean

No

Inherited disabled attribute accepted by FileTrigger.

onClickTavoEventHandler<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

ConcernContract
StateNo component state contract is exposed; the application owns the rendered content and surrounding behavior.
DOM targetNative 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

ContractCurrent value
Maturitystable
Categoryforms
Component import@tavojs/ui/file-trigger
Explicit CSS import@tavojs/ui/css/file-trigger
PreviewInteractive preview available on this page