#Removing Lexical default features and a field for links

1 messages · Page 1 of 1 (latest)

toxic pollen
#

Hey Payload Community, I could use your help with two questions relating to Lexical.

I am loving using Lexical but want to remove or disable some of the features that are included in defaultFeatures.

Is it possible to just pass in the features I want based on the feature name provide in the docs, like BoldTextFeature?

My next question is about including a link field within a collection. I know I can add links with Lexical but adding a whole Rich Text Editor field for a single link seems like overkill. Is there an alternative field that can handle links?

Thank you!

glad pythonBOT
strong gate
# toxic pollen Hey Payload Community, I could use your help with two questions relating to Lexi...

"Is it possible to just pass in the features I want based on the feature name provide in the docs, like BoldTextFeature?"

Yep! You don't have to use defaultFeatures - you can just pass them all in manually. Or use .filter() on defaultFeatures and filter unwanted features out manually. In the end defaultFeatures is just an opinionated array with lexical features pre-added.

My next question is about including a link field within a collection. I know I can add links with Lexical but adding a whole Rich Text Editor field for a single link seems like overkill.
You can use a text field for that! It doesn't handle stuff like validation or making the link clickable. You can add that to a text field using a custom validation function, as well as a custom field react component

glad pythonBOT
glacial flame
# strong gate > "Is it possible to just pass in the features I want based on the feature name ...

Filtering defaultFeatures skips most of them.
What am I doing wrong here? From this list only quote remain available after filtering

editor: lexicalEditor({
    features: ({ defaultFeatures, rootFeatures }) => {
        const allowedFeatures = [...defaultFeatures].filter((feature) => {
            const allowedKeys = [
                'bold',
                'italic',
                'underline',
                'strikethrough',
                'link',
                'blockquote',
                'toolbarInline',
            ]
            return allowedKeys.includes(feature.key)
        })

        return allowedFeatures
    },
}),