Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

206
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda