SIGN IN SIGN UP
payloadcms / payload UNCLAIMED

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.

0 0 0 TypeScript
2022-07-13 15:40:59 -07:00
---
title: Collapsible Field
label: Collapsible
order: 60
desc: With the Collapsible field, you can place fields within a collapsible layout component that can be collapsed / expanded.
2024-05-13 10:29:59 -04:00
keywords: row, fields, config, configuration, documentation, Content Management System, cms, headless, javascript, node, react, nextjs
2022-07-13 15:40:59 -07:00
---
2024-07-23 13:44:44 -04:00
The Collapsible Field is presentational-only and only affects the Admin Panel. By using it, you can place fields within a nice layout component that can be collapsed / expanded.
2022-07-13 15:40:59 -07:00
<LightDarkImage
srcLight="https://payloadcms.com/images/docs/fields/collapsible.png"
srcDark="https://payloadcms.com/images/docs/fields/collapsible-dark.png"
2024-07-11 09:54:21 -04:00
alt="Shows a Collapsible field in the Payload Admin Panel"
caption="Admin Panel screenshot of a Collapsible field"
/>
To add a Collapsible Field, set the `type` to `collapsible` in your [Field Config](./overview):
```ts
import type { Field } from 'payload'
export const MyCollapsibleField: Field = {
// ...
// highlight-start
type: 'collapsible',
fields: [
// ...
],
// highlight-end
}
```
## Config Options
2022-07-13 15:40:59 -07:00
| Option | Description |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`label`** \* | A label to render within the header of the collapsible component. This can be a string, function or react component. Function/components receive `({ data, path })` as args. |
| **`fields`** \* | Array of field types to nest within this Collapsible. |
| **`admin`** | Admin-specific configuration. [More details](#admin-options). |
| **`custom`** | Extension point for adding custom data (e.g. for plugins) |
2022-07-13 15:40:59 -07:00
_\* An asterisk denotes that a property is required._
2022-07-13 15:40:59 -07:00
## Admin Options
To customize the appearance and behavior of the Collapsible Field in the [Admin Panel](../admin/overview), you can use the `admin` option:
```ts
import type { Field } from 'payload'
export const MyCollapsibleField: Field = {
// ...
admin: {
// highlight-line
// ...
},
}
```
The Collapsible Field inherits all of the default admin options from the base [Field Admin Config](./overview#admin-options), plus the following additional options:
| Option | Description |
| ------------------- | ------------------------------- |
| **`initCollapsed`** | Set the initial collapsed state |
## Example
2022-07-13 15:40:59 -07:00
2022-08-23 11:43:24 -04:00
```ts
import type { CollectionConfig } from 'payload'
2022-08-23 11:43:24 -04:00
export const ExampleCollection: CollectionConfig = {
2022-07-13 15:40:59 -07:00
slug: 'example-collection',
fields: [
{
2022-11-16 13:35:00 -05:00
label: ({ data }) => data?.title || 'Untitled',
2022-07-13 15:40:59 -07:00
type: 'collapsible', // required
fields: [
// required
2022-11-15 12:37:47 -05:00
{
name: 'title',
type: 'text',
required: true,
},
2022-07-13 15:40:59 -07:00
{
name: 'someTextField',
type: 'text',
required: true,
},
],
},
],
2022-07-13 15:40:59 -07:00
}
```