Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

211
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda