File

import File from 'frui/fields/File';
Copy

Props

File accepts all props of a standard HTML Input element. See Moz for standard input attributes.

NameTypeRequiredNotes
classNamestringNoStandard HTML class names
defaultValuestringNoAlias to value
errorstring|booleanNoAny error message
namestringNoUsed for react server components.
onChangeFunctionNoEvent handler when value has changed
onUpdateFunctionNoUpdate event handler
onUploadFunctionYesCalled when file is loaded
passRefLegacyRefNoPasses ref to html input
styleCSS ObjectNoStandard CSS object
uploadingstringNoPhrased used when uploading files
valuestringNoDefault value

Basics

<File className="bg-white w-full" value="https://images.wsj.net/im-580612/8SR" />
Copy

Events

Files have an extra prop called onUpload. This is where you should add your logic for handling the file upload. Using this in combination with onUpdate will allow you to pass values from upload to form processing.

<File 
  className="bg-white w-full" 
  onUpload={(file, next) => {
    //just a mock call
    setTimeout(() => {
      next('https://images.wsj.net/im-580612/8SR')
    }, 5000)
  }} 
  onUpdate={value => alert(value)} 
/>
Copy

On Change

The onChange event is triggered when the value has changed. The following arguments are passed to the event handler:

NameTypeSample
eventEvent Objectsee: Change Event

On Upload

The onUpload event is triggered when a file has been selected. The following arguments are passed to the event handler:

NameTypeSample
fileFilesee: File Object
next(url: string) => void
next('//cdn.ex.com/img.jpg')

On Update

The onUpdate event is triggered when the value has been updated. The following arguments are passed to the event handler:

NameTypeSample
valuestring`foobar`

Errors

You can pass the error prop to highlight the input field red.

<File error={string|true} className="bg-white w-full" />
Copy

Custom Styles

You can add your own custom class to files or use any of the respective frui-field-file, frui-field-file-control, frui-field-file-reset, frui-field-file-file, and frui-field-file-link CSS classes.