Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

204
Views
Slatejs reset element type after line-break

I'm working with slatejs ,and I want to know :

If my current Element.type is title , looks like <h1></h1> ,
but when I click enter, it will create a new <h1> tag.

If I want the line-break after title type and the new element type will become default, what shoud I do ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Assuming your node looks something like: {children : [{text: ''}], type: 'title'} or something on the lines of this.

When you press enter, it adds an empty node like {children : [{text: ''}], type: 'title'}

You should be able to modify the insertBreak behaviour this way to modify the kind of node that it adds:

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: 'default'
        })
        return
      }
    }
    insertBreak()
  }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!