feat(richtext-lexical): ability to override default placeholder (#10278)
 
This commit is contained in:
@@ -45,7 +45,7 @@ _* An asterisk denotes that a property is required._
|
|||||||
|
|
||||||
## Admin Options
|
## Admin Options
|
||||||
|
|
||||||
The customize the appearance and behavior of the Rich Text Field in the [Admin Panel](../admin/overview), you can use the `admin` option:
|
The customize the appearance and behavior of the Rich Text Field in the [Admin Panel](../admin/overview), you can use the `admin` option. The Rich Text Field inherits all of the default options from the base [Field Admin Config](../admin/fields#admin-options)
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import type { Field } from 'payload'
|
import type { Field } from 'payload'
|
||||||
@@ -58,13 +58,7 @@ export const MyRichTextField: Field = {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The Rich Text Field inherits all of the default options from the base [Field Admin Config](../admin/fields#admin-options), plus the following additional options:
|
Further customization can be done with editor-specific options.
|
||||||
|
|
||||||
| Property | Description |
|
|
||||||
| ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------- |
|
|
||||||
| **`placeholder`** | Set this property to define a placeholder string for the field. |
|
|
||||||
| **`hideGutter`** | Set this property to `true` to hide this field's gutter within the Admin Panel. |
|
|
||||||
| **`rtl`** | Override the default text direction of the Admin Panel for this field. Set to `true` to force right-to-left text direction. |
|
|
||||||
|
|
||||||
## Editor-specific Options
|
## Editor-specific Options
|
||||||
|
|
||||||
|
|||||||
@@ -298,3 +298,43 @@ Make sure to only use types exported from `@payloadcms/richtext-lexical`, not fr
|
|||||||
### Automatic type generation
|
### Automatic type generation
|
||||||
|
|
||||||
Lexical does not generate the accurate type definitions for your richText fields for you yet - this will be improved in the future. Currently, it only outputs the rough shape of the editor JSON which you can enhance using type assertions.
|
Lexical does not generate the accurate type definitions for your richText fields for you yet - this will be improved in the future. Currently, it only outputs the rough shape of the editor JSON which you can enhance using type assertions.
|
||||||
|
|
||||||
|
## Admin customization
|
||||||
|
|
||||||
|
The Rich Text Field editor configuration has an `admin` property with the following options:
|
||||||
|
|
||||||
|
| Property | Description |
|
||||||
|
| ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
|
| **`placeholder`** | Set this property to define a placeholder string for the field. |
|
||||||
|
| **`hideGutter`** | Set this property to `true` to hide this field's gutter within the Admin Panel. |
|
||||||
|
|
||||||
|
### Disable the gutter
|
||||||
|
|
||||||
|
You can disable the gutter (the vertical line padding between the editor and the left edge of the screen) by setting the `hideGutter` prop to `true`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
{
|
||||||
|
name: 'richText',
|
||||||
|
type: 'richText',
|
||||||
|
editor: lexicalEditor({
|
||||||
|
admin: {
|
||||||
|
hideGutter: true
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Customize the placeholder
|
||||||
|
|
||||||
|
You can customize the placeholder (the text that appears in the editor when it's empty) by setting the `placeholder` prop:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
{
|
||||||
|
name: 'richText',
|
||||||
|
type: 'richText',
|
||||||
|
editor: lexicalEditor({
|
||||||
|
admin: {
|
||||||
|
placeholder: 'Type your content here...'
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ export const LexicalEditor: React.FC<
|
|||||||
contentEditable={
|
contentEditable={
|
||||||
<div className="editor-scroller">
|
<div className="editor-scroller">
|
||||||
<div className="editor" ref={onRef} tabIndex={-1}>
|
<div className="editor" ref={onRef} tabIndex={-1}>
|
||||||
<LexicalContentEditable />
|
<LexicalContentEditable editorConfig={editorConfig} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,15 +6,26 @@ import { useTranslation } from '@payloadcms/ui'
|
|||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
|
|
||||||
import './ContentEditable.scss'
|
import './ContentEditable.scss'
|
||||||
|
import type { SanitizedClientEditorConfig } from '../config/types.js'
|
||||||
|
|
||||||
export function LexicalContentEditable({ className }: { className?: string }): JSX.Element {
|
export function LexicalContentEditable({
|
||||||
|
className,
|
||||||
|
editorConfig,
|
||||||
|
}: {
|
||||||
|
className?: string
|
||||||
|
editorConfig: SanitizedClientEditorConfig
|
||||||
|
}): JSX.Element {
|
||||||
const { t } = useTranslation<{}, string>()
|
const { t } = useTranslation<{}, string>()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ContentEditable
|
<ContentEditable
|
||||||
aria-placeholder={t('lexical:general:placeholder')}
|
aria-placeholder={t('lexical:general:placeholder')}
|
||||||
className={className ?? 'ContentEditable__root'}
|
className={className ?? 'ContentEditable__root'}
|
||||||
placeholder={<p className="editor-placeholder">{t('lexical:general:placeholder')}</p>}
|
placeholder={
|
||||||
|
<p className="editor-placeholder">
|
||||||
|
{editorConfig?.admin?.placeholder ?? t('lexical:general:placeholder')}
|
||||||
|
</p>
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ export type LexicalFieldAdminProps = {
|
|||||||
* Controls if the gutter (padding to the left & gray vertical line) should be hidden. @default false
|
* Controls if the gutter (padding to the left & gray vertical line) should be hidden. @default false
|
||||||
*/
|
*/
|
||||||
hideGutter?: boolean
|
hideGutter?: boolean
|
||||||
|
/**
|
||||||
|
* Changes the placeholder text in the editor if no content is present.
|
||||||
|
*/
|
||||||
|
placeholder?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type LexicalEditorProps = {
|
export type LexicalEditorProps = {
|
||||||
|
|||||||
Reference in New Issue
Block a user