Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Rich text field missing editor

default discord avatar
frankie.d11 months ago
18

I've just set up a simple

richText

field with no additional configuration, and the attached screenshot is what I see.



My config uses the preset

@/fields/defaultLexical

editor, which should render as a proper WYSIWYG, but what I see is a single line with the ability to click one of the plus icons to add a paragraph.



What has gone wrong here?

  • default discord avatar
    zed054711 months ago

    Hey

    @321395600824467466



    Yeah this is intentional, the default functionality is included there. If you type

    /

    you will see a list of elements you can add. If you highlight some text, a floating menu should appear with more options

  • default discord avatar
    frankie.d11 months ago

    Looks like the only element I can add is a paragraph, and there are no additional UI elements on selection.





    The default config looks like it should at least have some basic formatting available, unless I'm misunderstanding how Lexical is set up?

    https://payloadcms.com/docs/rich-text/overview#features-overview

    Also, thanks for the quick response,

    @654031862146007055

    !

  • default discord avatar
    zed054711 months ago

    Is this the website template?

  • default discord avatar
    frankie.d11 months ago

    Yep!

  • default discord avatar
    zed054711 months ago

    Can you share the collection config of the field this is in?

  • default discord avatar
    frankie.d11 months ago

    Sure, let me grab that.



  • default discord avatar
    zed054711 months ago

    So this should be grabbing the lexical config you have set up in your root payload config - want to double check that your root config uses the defaultLexical object



    You can also try passing the editor directly into the field via

    description.editor

    {
      name: 'description',
      type: 'richText',
      editor: defaultLexical,
    },
  • default discord avatar
    frankie.d11 months ago

    I've tried that as well, but I'm having the same result. I'll give it another go. It flashes for a moment on initial render, then shrinks down. Let me try explicitly passing it real quick.



    Nope, passing it results in the same thing.



    This one's a headscratcher. I haven't added any packages to my knowledge, either. This is a vanilla set up.



    I've had a handful of little issues along the way and quite a few ones that have nearly been blocking. Hopefully this one doesn't end up too tough to solve, I'm determined to keep using Payload for this project.

  • default discord avatar
    zed054711 months ago

    Oh, you're missing a bunch of stuff here, seems like the default lexical helper object was updated to be super minimal



    One sec, I'll whip up a copy & paste solution here for ya

  • default discord avatar
    frankie.d11 months ago

    That'd do it lol. Thanks!

  • default discord avatar
    zed054711 months ago
    import type { TextFieldSingleValidation } from 'payload'
    import {
      LinkFeature,
      lexicalEditor,
      type LinkFields,
    } from '@payloadcms/richtext-lexical'
    
    export const defaultLexical = lexicalEditor({
      features: ({ defaultFeatures }) => [
        ...defaultFeatures,
        LinkFeature({
          enabledCollections: ['pages', 'posts'],
          fields: ({ defaultFields }) => {
            const defaultFieldsWithoutUrl = defaultFields.filter((field) => {
              if ('name' in field && field.name === 'url') return false
              return true
            })
    
            return [
              ...defaultFieldsWithoutUrl,
              {
                name: 'url',
                type: 'text',
                admin: {
                  condition: (_data, siblingData) => siblingData?.linkType !== 'internal',
                },
                label: ({ t }) => t('fields:enterURL'),
                required: true,
                validate: ((value, options) => {
                  if ((options?.siblingData as LinkFields)?.linkType === 'internal') {
                    return true // no validation needed, as no url should exist for internal links
                  }
                  return value ? true : 'URL is required'
                }) as TextFieldSingleValidation,
              },
            ]
          },
        }),
      ]
    })


    This doesn't include the

    FixedToolbarFeature

    or the

    BlocksFeature

    fyi

  • default discord avatar
    frankie.d11 months ago

    That looks like it does it! Thanks a ton. Should I just override the file itself for now?

  • default discord avatar
    zed054711 months ago
    Should I just override the file itself for now?

    Up to you honestly

  • default discord avatar
    frankie.d11 months ago

    Got it 👍


    Would you mind one more hopefully quick question while I've got you? My other blocking issue that hasn't had any traction.

  • default discord avatar
    zed054711 months ago

    The key here is the defaultFeatures being included now



    Go for it

  • default discord avatar
    frankie.d11 months ago

    Sweet, thank ya. Let me grab the summary from my other question

  • default discord avatar
    zed054711 months ago

    Or if you made a community help thread, you can just copy the link

  • default discord avatar
    frankie.d11 months ago

    Oh, didn't know I could copy the link. That makes it easier.



    https://discord.com/channels/967097582721572934/1391946819801579590
Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.