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
2023-08-08 15:00:21 +01: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"
2024-07-09 18:10:04 -04:00
caption="Admin Panel screenshot of a Collapsible field"
2023-08-08 15:00:21 +01:00
/>
2024-07-22 23:46:06 -04:00
To add a Collapsible Field, set the `type` to `collapsible` in your [Field Config](./overview):
```ts
2024-10-18 10:47:47 +03:00
import type { Field } from 'payload'
2024-07-22 23:46:06 -04:00
export const MyCollapsibleField: Field = {
// ...
// highlight-start
type: 'collapsible',
fields: [
// ...
],
// highlight-end
}
```
## Config Options
2022-07-13 15:40:59 -07:00
2022-09-12 13:39:49 -04:00
| Option | Description |
| --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
2025-03-14 11:13:08 -06:00
| **`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). |
2023-04-18 20:28:42 +01:00
| **`custom`** | Extension point for adding custom data (e.g. for plugins) |
2022-07-13 15:40:59 -07:00
2025-03-14 11:13:08 -06:00
_\* An asterisk denotes that a property is required._
2022-07-13 15:40:59 -07:00
2024-07-22 23:46:06 -04:00
## Admin Options
2025-02-11 13:37:23 -05:00
To customize the appearance and behavior of the Collapsible Field in the [Admin Panel](../admin/overview), you can use the `admin` option:
2024-07-22 23:46:06 -04:00
```ts
2024-10-18 10:47:47 +03:00
import type { Field } from 'payload'
2024-07-22 23:46:06 -04:00
export const MyCollapsibleField: Field = {
// ...
2025-03-14 11:13:08 -06:00
admin: {
// highlight-line
2024-07-22 23:46:06 -04:00
// ...
},
}
```
2022-09-12 13:39:49 -04:00
feat: select field filter options (#12487)
It is a common pattern to dynamically show and validate a select field's
options based on various criteria such as the current user or underlying
document.
Some examples of this might include:
- Restricting options based on a user's role, e.g. admin-only options
- Displaying different options based on the value of another field, e.g.
a city/state selector
While this is already possible to do with a custom `validate` function,
the user can still view and select the forbidden option...unless you
_also_ wired up a custom component.
Now, you can define `filterOptions` on select fields.
This behaves similarly to the existing `filterOptions` property on
relationship and upload fields, except the return value of this function
is simply an array of options, not a query constraint. The result of
this function will determine what is shown to the user and what is
validated on the server.
Here's an example:
```ts
{
name: 'select',
type: 'select',
options: [
{
label: 'One',
value: 'one',
},
{
label: 'Two',
value: 'two',
},
{
label: 'Three',
value: 'three',
},
],
filterOptions: ({ options, data }) =>
data.disallowOption1
? options.filter(
(option) => (typeof option === 'string' ? options : option.value) !== 'one',
)
: options,
}
```
2025-05-22 15:54:12 -04:00
The Collapsible Field inherits all of the default admin options from the base [Field Admin Config](./overview#admin-options), plus the following additional options:
2022-09-12 13:39:49 -04:00
| Option | Description |
| ------------------- | ------------------------------- |
| **`initCollapsed`** | Set the initial collapsed state |
2024-06-05 17:08:15 -04:00
## Example
2022-07-13 15:40:59 -07:00
2022-08-23 11:43:24 -04:00
```ts
2024-10-18 10:47:47 +03:00
import type { CollectionConfig } from 'payload'
2022-08-23 11:43:24 -04:00
2023-05-01 16:28:13 -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,
},
],
2023-09-01 17:39:44 +02:00
},
],
2022-07-13 15:40:59 -07:00
}
```