Adding text alignment to the Rich Text Editor in Sanity & Next and displaying live changes.

5 replies
Last updated: Dec 1, 2022
Hello, my name is Lars, I am a new developer trying my way forward with Sanity & Next, i kinda enjoy using Sanity, but I do have one major question.The "Rich Text Editor" or "Portable text editor" does not support text alignment right off the bat? What is going on here?
How do i add it to my RTF editor, and actually display the changes live? ( on the editor. ) - my schema below.
Nov 23, 2022, 6:55 PM
export default {
  title: 'Block Content',
  name: 'blockContent',
  type: 'array',
  of: [
    {
      title: 'Block',
      type: 'block',
      styles: [
        { title: 'Normal', value: 'normal' },
        { title: 'H1', value: 'h1' },
        { title: 'H2', value: 'h2' },
        { title: 'H3', value: 'h3' },
        { title: 'H4', value: 'h4' },
        { title: 'Quote', value: 'blockquote' },
      ],
      lists: [{ title: 'Bullet', value: 'bullet' }],
      marks: {
        decorators: [
          { title: 'Strong', value: 'strong' },
          { title: 'Emphasis', value: 'em' },
        ],
        annotations: [
          {
            title: 'URL',
            name: 'link',
            type: 'object',
            fields: [
              {
                title: 'URL',
                name: 'href',
                type: 'url',
              },
            ],
          },
        ],
      },
    },
    {
      type: 'image',
      fields: [
        {
          type: 'text',
          name: 'alt',
          title: 'Alternative text',
          description: `Some of your visitors cannot see images, 
            be they blind, color-blind, low-sighted; 
            alternative text is of great help for those 
            people that can rely on it to have a good idea of 
            what\'s on your page.`,
          options: {
            isHighlighted: true,
            hotspot: true,
          }
        }
      ]
    }
  ],
}

Nov 23, 2022, 6:56 PM
Hello ☺️Since the portable text editor is front-end agnostic, we add only the things we all need, but make
customisation possible. You would need to setup a custom style and adding some CSS.
Nov 24, 2022, 1:11 AM
I was already able to make it go left - center - right, but for user experience, i would love to show the user the changes, inside of the editor, is that possible?
Nov 24, 2022, 8:31 AM
Yeah you would have to set this up through the editor renderer
Nov 24, 2022, 6:07 PM
Thanks! sorry for the late reply, it worked 🙂
Dec 1, 2022, 10:55 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?