React Native MantineInputs

FileInput

Pick files with the native document picker

Import: import { FileInput } from 'react-native-mantine';

Usage

import { FileInput } from 'react-native-mantine';
import type { PickedFile } from 'react-native-mantine';

const [file, setFile] = useState<PickedFile | null>(null);

<FileInput
  label="Attachment"
  placeholder="Press to pick a file"
  value={file}
  onChange={setFile}
  accept="application/pdf"
  clearable
/>

// Multiple files with custom value component
<FileInput
  multiple
  valueComponent={({ value }) => (
    <Group spacing={4}>
      {value.map((file) => (
        <Pill key={file.uri}>{file.name}</Pill>
      ))}
    </Group>
  )}
/>

Props

PropTypeDefaultDescription
valuePickedFile | PickedFile[] | nullValue for controlled component, array with multiple and a single file otherwise
defaultValuePickedFile | PickedFile[] | nullDefault value for uncontrolled component
onChange(value: PickedFile | PickedFile[] | null) => voidCalled when the selection changes
multiplebooleanfalseDetermines whether user can pick more than one file
acceptstring | string[]Mime type(s) of the files that can be picked, e.g. "application/pdf"
placeholderstringDisplayed when no file is selected
clearablebooleanfalseAdds a clear button to the right section when a file is selected
clearButtonLabelstring"Clear"Clear button accessibility label
valueComponent({ value }) => React.ReactNodeCustom component to render the selected value
labelReact.ReactNodeInput label, inherited from InputBase
descriptionReact.ReactNodeInput description, inherited from InputBase
errorReact.ReactNodeError message, inherited from InputBase
requiredbooleanDisplays required asterisk, inherited from InputBase
disabledbooleanDisables interaction and dims the input, inherited from InputBase

Source on GitHub · npm