Files
payload/test/lexical/collections/LexicalLinkFeature/index.ts
Paul 3e7db302ee fix(richtext-lexical): newTab not being able to be checked to true by default (#12389)
Previously the value of new tab checkbox in the link feature was not
able to be set to true by default because we were passing `false` as a
default value.

This fixes that and adds test coverage for customising that link drawer.
2025-05-15 15:57:23 +00:00

45 lines
1.1 KiB
TypeScript

import type { CheckboxField, CollectionConfig } from 'payload'
import {
FixedToolbarFeature,
lexicalEditor,
LinkFeature,
TreeViewFeature,
} from '@payloadcms/richtext-lexical'
import { lexicalLinkFeatureSlug } from '../../slugs.js'
export const LexicalLinkFeature: CollectionConfig = {
slug: lexicalLinkFeatureSlug,
labels: {
singular: 'Lexical Link Feature',
plural: 'Lexical Link Feature',
},
fields: [
{
name: 'richText',
type: 'richText',
editor: lexicalEditor({
features: ({ defaultFeatures }) => [
...defaultFeatures,
TreeViewFeature(),
LinkFeature({
fields: ({ defaultFields }) => {
const modifiedFields = defaultFields.map((field) => {
if (field.name === 'newTab') {
return { ...field, defaultValue: true } as CheckboxField
}
return field
})
return [...modifiedFields, { type: 'text', name: 'someText' }]
},
}),
FixedToolbarFeature(),
],
}),
},
],
}