You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improves documentation for custom upload components. Fixes#14013
Changes:
- Adds "Customizing the Upload UI" section to upload/overview.mdx with
working examples
- Fixes Upload component example in custom-components/edit-view.mdx
- Adds warning about common mistake of using plain input elements
- Clarifies component export syntax (default vs named exports) in
overview.mdx
- Includes advanced examples with custom actions, drawers, and hooks
- Adds comparison table for upload collection vs upload field
customization
For more details on customizing upload components, including examples with custom actions and drawers, see the [Upload documentation](../upload/overview#customizing-the-upload-ui).
Copy file name to clipboardExpand all lines: docs/custom-components/overview.mdx
+19-1Lines changed: 19 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,9 @@ In order to ensure the Payload Config is fully Node.js compatible and as lightwe
61
61
62
62
Component Paths, by default, are relative to your project's base directory. This is either your current working directory, or the directory specified in `config.admin.importMap.baseDir`.
63
63
64
-
Components using named exports are identified either by appending `#` followed by the export name, or using the `exportName` property. If the component is the default export, this can be omitted.
64
+
Components using named exports are identified either by appending `#` followed by the export name, or using the `exportName` property. If the component is the default export, the `#` and export name can be omitted.
65
+
66
+
**Both default exports and named exports are fully supported.** Choose the pattern that works best for your codebase.
65
67
66
68
```ts
67
69
import { buildConfig } from'payload'
@@ -87,6 +89,22 @@ const config = buildConfig({
87
89
88
90
In this example, we set the base directory to the `src` directory, and omit the `/src/` part of our component path string.
89
91
92
+
**Examples of component path syntax:**
93
+
94
+
```ts
95
+
// Named export using hash syntax
96
+
Button: '/components/Logout#MyComponent'
97
+
98
+
// Default export (no hash needed)
99
+
Button: '/components/Logout'
100
+
101
+
// Named export using exportName property
102
+
Button: {
103
+
path: '/components/Logout',
104
+
exportName: 'MyComponent',
105
+
}
106
+
```
107
+
90
108
### Component Config
91
109
92
110
While Custom Components are usually defined as a string, you can also pass in an object with additional options:
You can completely customize the upload interface in the Admin Panel by swapping in your own React components. This allows you to modify how files are uploaded, add custom fields, integrate custom actions, or enhance the upload experience.
336
+
337
+
### Upload Component Configuration
338
+
339
+
To customize the upload UI for an upload-enabled collection, use the `admin.components.edit.Upload` property in your [Collection Config](../configuration/collections):
Custom upload components must integrate with Payload's form system to work correctly. The recommended approach is to use Payload's built-in `<Upload>` component from `@payloadcms/ui` and wrap it with additional functionality.
366
+
367
+
<Bannertype="warning">
368
+
You should not use a simple `<input type="file" />` element
369
+
alone. It will not connect to Payload's upload API or form state, resulting
370
+
in errors like "400 Bad Request - no file uploaded." Always use Payload's
371
+
`<Upload>` component or properly integrate with form hooks.
372
+
</Banner>
373
+
374
+
#### Basic Example
375
+
376
+
Here's a minimal example showing how to create a custom upload component:
|**Upload Collection Customization**|`admin.components.edit.Upload`| Customize the UI when editing documents in an upload-enabled collection (e.g., the Media collection edit view) |
499
+
|**Upload Field Customization**|`admin.components.Field` on an upload field | Customize the field that references uploads in other collections (e.g., a "Featured Image" field on a Posts collection) |
500
+
501
+
**Example of Upload Field Customization:**
502
+
503
+
```ts
504
+
importtype { CollectionConfig } from'payload'
505
+
506
+
exportconst Posts:CollectionConfig= {
507
+
slug: 'posts',
508
+
fields: [
509
+
{
510
+
name: 'featuredImage',
511
+
type: 'upload',
512
+
relationTo: 'media',
513
+
admin: {
514
+
components: {
515
+
Field: '/components/CustomUploadField',
516
+
},
517
+
},
518
+
},
519
+
],
520
+
}
521
+
```
522
+
523
+
For more details on customizing fields, see [Field Components](../fields/overview#custom-components).
524
+
525
+
### Component Export Syntax
526
+
527
+
Custom components are referenced using file paths. Both default exports and named exports are supported:
0 commit comments