Inheritance of styles in new paragraph in slate.js

722 Views Asked by At

How do I prevent the next text block to inherit the same styles as the first one? If I add an heading and then press enter I would like it to be a paragraph on the next line, and not another heading.

2

There are 2 best solutions below

0
On
0
On

You can have a custom plugin like this for the editor

const { insertBreak } = editor
editor.insertBreak = () => {
  const { selection } = editor
    if (selection) {
       const [title] = Editor.nodes(editor, {
       match: n =>
       !Editor.isEditor(n) &&
       Element.isElement(n) &&
       (n.type === 'title')
      })
        
      if(title){
       Transforms.insertNodes(editor, {
        children: [{text: ""}],
        type: 'paragraph'
       })
       return
      }
    }
  insertBreak()
}