Creating a custom divider component in Sanity Studio

8 replies
Last updated: Jul 5, 2022
is it possible to create an empty object? I want to create a divider component that would have no fields on it, but running into an issue having no fields
AI Update

Yes, you can create a divider component without fields in Sanity! While Sanity schemas typically require at least one field, there are a few workarounds the community uses:

Simple workaround: Hidden field

The easiest approach is to add a single field with hidden: true:

{
  name: 'divider',
  type: 'object',
  title: 'Divider',
  fields: [
    {
      name: 'placeholder',
      type: 'string',
      hidden: true
    }
  ]
}

This satisfies Sanity's requirement for at least one field while keeping your Studio UI clean.

Better approach: Custom input component

For a more polished solution, you can use a custom input component with Sanity UI to render a visual divider:

// createDivider.js
import React from 'react'
import { Container } from '@sanity/ui'

export function createDivider({title}) {
  return {
    inputComponent: () => (
      <Container width={100} padding={4}>
        {/* Your custom divider styling here */}
      </Container>
    ),
    name: `divider${Math.random().toString(16).slice(2)}`,
    title,
    type: "string",
  }
}

// In your schema
import { createDivider } from './createDivider'

export default {
  name: 'myDocument',
  type: 'document',
  fields: [
    // ... other fields
    createDivider("Section Break"),
    // ... more fields
  ]
}

This approach gives you full control over the visual appearance and lets you create reusable divider components throughout your schemas. You can style it however you need using Sanity UI components.

The custom component approach is particularly useful if you want to add visual separation between field groups or create section headers in your Studio forms. There's even a GitHub repo with custom Studio components that includes dividers and other helpful utilities you can reference!

I just add hidden:true to a random field inside if I need this
What User said is probably fine enough.
There is even a better Option for inserting non-sanity components into your studio (in V2, V3 makes basically everything possible πŸ˜‰ )One way is to use the
Sanity UI in your schemas, which help keep the UI of your studio nice and clean.An example could be:


//Divider.js
import React from 'react'

import {
  Tooltip,
  Text,
  Box,
  TextInput
} from '@sanity/ui'


// This can be styled any way you need :) 
export function createDivider({title}) {
      return {
        inputComponent: (field) => (
            <div <Container width={100} padding={4}/>),
        name: `divider${"id" + Math.random().toString(16).slice(2)}`,
        title,
        type: "string",
}


// schema where you wanna use the Divider 

import { createDivider } from "../../src/components/createDivider";


export default {
  name: 'simple',
  title: 'Simple example',
  type: 'document',
  fields: [
    {
...,
  createDivider("seo"), // the string is just the title, which can be handy as a concept :) 
...
    }
  ]
} 
Hot damn, that looks cool!
Some changes, some bling bling and here we go: You can even use groups, descriptions etc.If you want to see more happen
πŸ˜‰ I’m happy to share my whole code πŸ’…
Dayyuumm. Nice User!
You should see my whole createDescription (where we can insert internal sanity links, etc. 😎 )
So here you go, a nice little bundle of custom inputs to make the studio yours πŸ§‘β€πŸŽ¨
πŸ‘‰ Custom Components in the Studio

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.

Was this answer helpful?