Skip to content

File Trigger

Github icon-storybook-square Storybook Markdown Copy for LLM

The FileTrigger component provides a way to trigger file selection dialogs, allowing users to upload files or select directories.

Import

import { FileTrigger } from "@cfa/react-core";

Live Editor

Guidelines

When to use

  • FileTrigger wraps a visible pressable trigger, usually a Button, to open the native file picker while keeping full control of trigger styling.

Do

  • Use clear action text on the trigger, such as Choose file, Select files, or Upload document. Use plural wording when multiple selection is allowed.
  • Put file type and size limits in supporting text when needed, such as PDF or JPG up to 10MB.
  • Use a Button trigger for primary upload actions. Use Link-style underlined text for inline attach flows, such as Attach files.
  • Pair with DropZone for drag-and-drop. Keep FileTrigger as the click-to-select path beside the drop area.
  • Follow selection with Progress Bar or status updates when upload progress matters.
  • Constrain allowed file types with the accept attribute. Do not rely on JavaScript validation alone.

Avoid

  • Using FileTrigger when native file input styling is enough and no custom trigger is needed.
  • Using FileTrigger for non-file actions. Use Button or Link directly.
  • Using FileTrigger as the only upload path when drag-and-drop is supported. Keyboard and assistive-tech people cannot drag.

Examples

Basic Usage

Simply wrap a Button component with FileTrigger to create a file upload button.

Multiple File Selection

Enable users to select multiple files by setting the allowsMultiple prop to true.

Accepted File Types

Restrict the types of files that can be selected by specifying the acceptedFileTypes prop.

Directory Selection

Allow users to select directories instead of files by setting the acceptDirectory prop to true.

Handling Selected Files

Use the onSelect callback to process files after they’ve been selected.