How to add static text to Sanity document without user input field?
No worries about asking an "old question" – this comes up fairly often! The solution is to create a custom input component that displays static text without actually rendering an editable field.
The approach from that linked answer page is still valid. Here's the basic idea:
1. Create a custom input component that just displays your text:
// components/IntroTextComponent.js
import React from 'react'
import {Card, Text} from '@sanity/ui'
export default function IntroText(props) {
const {type} = props
const {intro} = type.options || {}
return (
<Card padding={3} radius={2} shadow={1}>
<Text>{intro}</Text>
</Card>
)
}2. Add it to your schema with the text you want to display:
import IntroTextComponent from './components/IntroTextComponent'
export default {
name: 'myDocument',
type: 'document',
fields: [
{
name: 'welcomeText',
title: 'Welcome',
type: 'string',
components: {
input: IntroTextComponent
},
options: {
intro: 'Hello!\n\nThis is the homepage, where you can edit the main content.'
},
hidden: true // Optional: hides it from the field list
},
// ... your other fields
]
}Note for Studio v3: The syntax has changed slightly from the old answer. You now use components: { input: YourComponent } instead of inputComponent.
You can make this more sophisticated by:
- Using Portable Text in the
introoption for formatted text - Adding dynamic values from the document using
props.valueor other field values - Styling it with Sanity UI components to match your Studio theme
If you want the text to appear but not take up space in the document data, you can also set hidden: true on the field, or use readOnly: true with an initialValue if you need it stored but not editable.
Show original thread6 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.