---
title: FileInput
description: "`FileInput`は、ユーザーがファイルを選択するために使用されるコンポーネントです。"
links:
- style: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/file-input/file-input.style.ts
- source: https://github.com/yamada-ui/yamada-ui/tree/main/packages/react/src/components/file-input
- storybook: https://yamada-ui.github.io/yamada-ui?path=/story/components-fileinput--basic
---
```tsx
```
## 使い方
```tsx
import { FileInput } from "@yamada-ui/react"
```
```tsx
import { FileInput } from "@/components/ui"
```
```tsx
import { FileInput } from "@workspaces/ui"
```
```tsx
```
### バリアントを変更する
```tsx
{(variant, index) => (
)}
```
### サイズを変更する
```tsx
{(size, index) => (
)}
```
### カラースキームを変更する
```tsx
{(colorScheme, index) => (
)}
```
### 複数選択を許容する
複数選択を許容する場合は、`multiple`を`true`に設定します。
```tsx
```
### 拡張子を指定する
拡張子を指定する場合は、`accept`に文字列(タイプ)を設定します。
```tsx
```
### 区切りをカスタマイズする
区切りをカスタマイズする場合は、`separator`に文字列を設定します。
```tsx
```
### カスタムコンポーネントを使う
カスタムコンポーネントを使う場合は、`component`に`ReactNode`を設定します。`component`は、`value`(`File`)と`index`を提供します。
```tsx
{name}}
gapY="xs"
multiple
placeholder="Please upload file"
/>
```
### ファイル名を整形する
ファイル名を整形する場合は、`format`を使用します。`format`は、`File`を提供します。
```tsx
name.substring(0, name.indexOf("."))}
multiple
placeholder="Please upload file"
/>
```
### 子要素をカスタマイズする
子要素をカスタマイズする場合は、`children`を使用します。`children`は、`File`を配列で提供します。
```tsx
{(files) => Selected: {files?.length ?? 0}}
```
### アドオンを追加する
アドオンを追加する場合は、`FileInput`を`InputGroup.Root`でラッピングし、`InputGroup.Addon`を使用します。
```tsx
```
### 要素を追加する
要素を追加する場合は、`FileInput`を`InputGroup.Root`でラッピングし、`InputGroup.Element`を使用します。
```tsx
```
### 無効にする
無効にする場合は、`disabled`を`true`に設定します。
```tsx
```
### 読み取り専用にする
読み取り専用にする場合は、`readOnly`を`true`に設定します。
```tsx
```
### 無効な入力にする
無効な入力にする場合は、`invalid`を`true`に設定します。
```tsx
```
### ボーダーの色を変更する
ボーダーの色を変更する場合は、`focusBorderColor`または`errorBorderColor`に値を設定します。
```tsx
```
### リセットする
値をリセットする場合は、`resetRef`に`ref`を設定します。設定された`ref`にコールバック関数が付与されるので、それを実行します。
```tsx
const [value, onChange] = useState(undefined)
const resetRef = useRef<() => void>(null)
const onReset = () => {
onChange(undefined)
resetRef.current?.()
}
return (
files: {value?.length ?? 0}
{value?.length ? (
) : null}
)
```
## Props
| Prop | Default | Type | Description |
| ------------------ | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------ |
| `as` | - | `As` | The HTML element to render. |
| `asChild` | - | `boolean` | Merges its props onto its immediate child. |
| `css` | - | `CSSObject \| CSSObject[]` | The CSS object. |
| `colorScheme` | - | `"amber" \| "black" \| "blackAlpha" \| "blue" \| "cyan" \| "danger" \| "emerald" \| "error" \| "flashy" \| "fuchsia" ...` | Set color scheme variables. |
| `size` | `"md"` | `"2xl" \| "lg" \| "md" \| "sm" \| "xl" \| "xs"` | The size of the component. |
| `variant` | `"outline"` | `"filled" \| "flushed" \| "outline" \| "plain"` | The variant of the component. |
| `children` | - | `(files: File[] \| undefined) => ReactNode` | A callback that returns a React node. |
| `component` | - | `(props: { index: number; value: File }) => ReactNode` | The component that displays uploaded files. |
| `defaultValue` | - | `File[]` | The initial value of the file input. |
| `errorBorderColor` | - | `"-moz-initial" \| "ActiveBorder" \| "ActiveCaption" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" \| "amber.400" \| "amber.50" \| "amber.500" ...` | The border color when the input is invalid. |
| `focusBorderColor` | - | `"-moz-initial" \| "ActiveBorder" \| "ActiveCaption" \| "aliceblue" \| "amber.100" \| "amber.200" \| "amber.300" \| "amber.400" \| "amber.50" \| "amber.500" ...` | The border color when the input is focused. |
| `format` | - | `(value: File, index: number) => string` | A callback that formats the name of the uploaded file. |
| `invalid` | `false` | `boolean` | If `true`, the field will be invalid. |
| `onChange` | - | `(files: File[] \| undefined) => void` | Function to be called when a file change event occurs. |
| `resetRef` | - | `RefObject<(() => void) \| null>` | Ref to a reset function. |
| `separator` | `","` | `string` | The string to separate uploaded files. |
| `value` | - | `File[]` | The value of the file input. |
## アクセシビリティ
現在、v2の移行に伴い、このセクションは更新中です。