nextjs-cms

textAreaField

A multi-line plain-text input. Descriptions, excerpts, addresses, notes.

import { textAreaField } from 'nextjs-cms/core/fields'

Basic usage

textAreaField({ name: 'description' })

With every option

textAreaField({
    name: 'excerpt',
    label: { en: 'Excerpt', ar: 'مقتطف' },
    required: true,
    order: 3,
    localized: true,
    conditionalRules: [{ field: showExcerpt, condition: 'equals', value: true }],

    placeholder: 'One or two sentences shown on listing pages',
    minLength: 50,
    maxLength: 300,
    sanitize: true,
    rtl: false,
})

Options

OptionTypeDefaultDescription
placeholderstringnoneHint shown in the empty textarea.
minLengthnumbernoneMinimum number of characters.
maxLengthnumbernoneMaximum number of characters. Unlike textField, it does not change the column (always LONGTEXT).
sanitizebooleanfalseHTML-escape the value before saving. See textField sanitize.
rtlbooleanlocale-basedForce the text direction. See textField rtl.
defaultValuestringnonePre-filled value.

Plus the common options.

Options in detail

maxLength for SEO fields

Search engines truncate meta descriptions around 155–160 characters. Enforce it:

textAreaField({ name: 'meta_description', label: 'Meta description', maxLength: 160 })

Line breaks

The value is stored exactly as typed, including newlines (\n). To display paragraphs on your website:

export function Multiline({ text }: { text: string }) {
    return <p className='whitespace-pre-line'>{text}</p>
}

Need bold, links, or lists? Use richTextField instead.

Storage

ColumnLONGTEXT CHARACTER SET utf8mb4
ValuePlain text with \n line breaks