Custom slug input component for dynamic URL description without schema changes

4 replies
Last updated: Jan 29, 2026
If I wanted to have the "slug" input show a description underneath that revealed the full (intended) URL to my site, am I right in thinking that would require a custom input component, since "description" appears to be a normal property?
Also, if I am "just" changing the component itself, I don't have to have a new/different schema/field and experience data loss if the slug fields already exist, correct? It's just a different way to "dress up" the field produced ( a misnomer, I know, since it's functional as well as aesthetic -- I am just thinking in terms of, it's all just a different way to get data stored into the system, still )
AI Update

You're absolutely correct on both counts!

Yes, you need a custom input component to show a dynamic description under the slug field. The description property in Sanity schemas is indeed a static string, so if you want to display something dynamic (like showing the full intended URL based on the current slug value), you'll need to create a custom input component.

And yes, you won't experience data loss when switching to a custom input component. You're spot on with your thinking - the custom component is just a different way to "dress up" the field. The underlying data structure remains the same. As long as your custom component:

  1. Uses the same field name (slug)
  2. Uses the same field type (slug)
  3. Properly implements the input component interface (receiving and handling the value, onChange, etc.)

...your existing slug data will work seamlessly with the new component. You're essentially just changing the UI layer while the data layer stays intact.

Here's a basic example of what a custom slug input component might look like:

import { Stack, Text } from '@sanity/ui'
import { StringInputProps, set, unset } from 'sanity'

export function CustomSlugInput(props: StringInputProps) {
  const { value, onChange, renderDefault } = props
  const slug = value?.current || ''
  
  // Your site's base URL
  const fullUrl = `https://yoursite.com/${slug}`
  
  return (
    <Stack space={2}>
      {/* Render the default slug input behavior */}
      {renderDefault(props)}
      
      {/* Dynamic description showing full URL */}
      {slug && (
        <Text size={1} muted>
          Full URL: <strong>{fullUrl}</strong>
        </Text>
      )}
    </Stack>
  )
}

Then in your schema, you'd add it like this:

{
  name: 'slug',
  type: 'slug',
  options: {
    source: 'title'
  },
  components: {
    input: CustomSlugInput
  }
}

The key here is using renderDefault(props) which renders the standard slug input (including the "Generate" button), and then you're just adding your dynamic description below it. This approach preserves all the built-in slug functionality while adding your custom UI enhancement.

Show original thread
4 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.

Was this answer helpful?