Single Line

Loading...
Files
components/single-line-demo.tsx
'use client';

import React from 'react';

import { Plate } from '@udecode/plate/react';
import { SingleLinePlugin } from '@udecode/plate-break/react';

import { editorPlugins } from '@/components/editor/plugins/editor-plugins';
import { useCreateEditor } from '@/components/editor/use-create-editor';
import { singleLineValue } from '@/components/values/single-line-value';
import { Editor, EditorContainer } from '@/components/plate-ui/editor';

export default function SingleLineDemo() {
  const editor = useCreateEditor({
    plugins: [...editorPlugins, SingleLinePlugin],
    value: singleLineValue,
  });

  return (
    <Plate editor={editor}>
      <EditorContainer variant="demo">
        <Editor />
      </EditorContainer>
    </Plate>
  );
}

Features

  • Limits editor to one block of text
  • Suitable for brief content or titles

Installation

npm install @udecode/plate-break

Usage

import { SingleLinePlugin } from '@udecode/plate-break/react';
 
const plugins = [
  // ...otherPlugins
  SingleLinePlugin,
];

Plugins

SingleLinePlugin

Plugin that restricts editor content to a single line of text.

Options

Collapse all

    Prevent extra spacing between blocks.

    • Default: true

    Prevent creation of new blocks.

    • Default: true

Example:

const plugins = [
  SingleLinePlugin.configure({
    options: {
      disableExtraSpacing: true,
      disableBlocks: true,
    },
  }),
];

Behavior:

  1. Prevents creation of new blocks with Enter key
  2. Removes extra spacing between blocks
  3. Maintains single block structure
  4. Ideal for title fields or single-line inputs