How AI is powering better personalization in e-commerce [with Vercel]. Sign up now

How to add and access options in Sanity custom type definitions?

3 repliesLast updated: Nov 29, 2025

If I'm creating a new custom type - like
localeBlock
- how can I add options to this type, and then access them inside of my definition?
Code in thread.
AI Update

When creating custom types in Sanity, you can add options to your type definition and access them within your schema. Here's how it works:

Adding Options to Custom Types

Options are defined within an options object in your schema definition. For example:

{
  type: 'object',
  name: 'localeBlock',
  title: 'Localized Block',
  options: {
    collapsible: true,
    collapsed: false,
    columns: 2,
    modal: {
      type: 'dialog',
      width: 'medium'
    }
  },
  fields: [
    // your fields here
  ]
}

Common Options for Objects

According to the object type documentation, you can use these options:

Accessing Options in Your Definition

If you need to access options programmatically within custom components or input components, you can access them through the schema type context:

// In a custom input component
const MyCustomInput = (props) => {
  const options = props.schemaType.options
  
  // Access specific options
  const isCollapsible = options?.collapsible
  const columnCount = options?.columns
  
  // Use them in your component logic
  return (
    // your component JSX
  )
}

Field-Level vs Type-Level Options

Remember that options can be defined at both the type level (affecting all instances) and when you use the type in a field:

// In your schema
fields: [
  {
    name: 'myLocaleBlock',
    type: 'localeBlock',
    options: {
      // These override the type-level options for this specific field
      collapsed: true
    }
  }
]

The field-level options will override type-level options when both are present. This gives you flexibility to set defaults at the type level while customizing behavior for specific field instances.

Show original thread
3 replies

Was this answer helpful?

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.

Related contributions