How to add headings and descriptive content to Sanity fieldsets?
Great question! You have two main options for adding headings and contextual content to organize your fields in Sanity Studio: fieldsets and field groups.
Fieldsets (Best for your use case)
Fieldsets are perfect for what you're describing. They let you group related fields together with a title and description to provide context. Here's how to use them:
defineType({
name: 'myDocument',
type: 'document',
fields: [
defineField({
name: 'title',
type: 'string',
}),
defineField({
name: 'author',
type: 'string',
fieldset: 'metadata',
}),
defineField({
name: 'publishDate',
type: 'datetime',
fieldset: 'metadata',
}),
],
fieldsets: [
{
name: 'metadata',
title: 'Publication Metadata',
description: 'These fields control when and how this article is published',
options: { collapsible: true, collapsed: false }
}
]
})The fieldsets array is where you define your headings and descriptions, then you assign fields to a fieldset using the fieldset property. You can even make them collapsible to reduce visual clutter!
Field Groups (Alternative approach)
Field Groups create tabbed interfaces instead of visual sections. They're great when you have many fields and want to organize them into separate tabs:
defineType({
name: 'myDocument',
type: 'document',
groups: [
{
name: 'seo',
title: 'SEO',
description: 'Search engine optimization settings'
},
{
name: 'content',
title: 'Content'
}
],
fields: [
defineField({
name: 'metaTitle',
type: 'string',
group: 'seo',
}),
defineField({
name: 'body',
type: 'text',
group: 'content',
}),
]
})Which should you use?
- Fieldsets: When you want visual sections with headings within the same view (sounds like what you need!)
- Field Groups: When you have lots of fields and want to split them into separate tabs
Both support titles and descriptions to give editors context about what the fields relate to. The Studio Excellence course has great examples of using both to create an excellent editorial experience.
Hope this helps! Let me know how it goes š
Show original thread8 replies
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.