How to create nested sub-categories in Sanity documents?
Based on your mockup, it sounds like you're looking for fieldsets! This is exactly the feature that lets you create those visual sub-categories/groupings within your document schema.
Fieldsets allow you to group related fields together under a collapsible section without changing your data structure. Here's how to set them up:
export default {
name: 'myDocument',
type: 'document',
title: 'My Document',
fieldsets: [
{
name: 'seoGroup',
title: 'SEO Settings',
options: {
collapsible: true, // Makes it collapsible
collapsed: false // Set to true if you want it collapsed by default
}
},
{
name: 'mediaGroup',
title: 'Media',
options: {
collapsible: true,
collapsed: true
}
}
],
fields: [
{
name: 'title',
type: 'string',
title: 'Title'
},
{
name: 'metaTitle',
type: 'string',
title: 'Meta Title',
fieldset: 'seoGroup' // Assigns this field to the SEO fieldset
},
{
name: 'metaDescription',
type: 'text',
title: 'Meta Description',
fieldset: 'seoGroup'
},
{
name: 'featuredImage',
type: 'image',
title: 'Featured Image',
fieldset: 'mediaGroup'
}
]
}The key parts are:
- Define your fieldsets in the
fieldsetsarray at the document level - Reference them by name in each field using
fieldset: 'yourFieldsetName' - Use the
optionsobject to control collapsibility and default state
You can also arrange fields in columns within a fieldset by adding columns: 2 to the options. Check out the guide on creating effective editor experiences for more tips on organizing your schemas!
Show original thread1 reply
Sanity β Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.