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

147
Vistas
How can I keep drag event handlers when the source dom node is removed?

I have a drawer (side panel) which opens up to display a set of 'widget types'. The idea is that i can drag these widget types out of the drawer and drop them into a grid as the type of widget they represent. I want to be able to close the drawer when drag starts, and then re-open it after i have stopped dragging (dropped the element). Each of the widget types in the drawer is some card wrapped in a 'draggable container'. This container implementation is shown below:

const DraggableContainer = ({ children, widgetType, onDragEnd, onDragStart }: Props) => {
  // ----- Return Component -----
  return (
    <div
      className="droppable-element"
      draggable={true}
      unselectable="on"
      // this is a hack for firefox
      // Firefox requires some kind of initialization
      // which we can do by adding this attribute
      // @see https://bugzilla.mozilla.org/show_bug.cgi?id=568313
      onDragStart={(e) => {
        e.dataTransfer.setData('text/plain', '');
        e.dataTransfer.setData('widgetType', widgetType);
        onDragStart && onDragStart();
      }}
      onDragEnd={(e) => {
        console.log('ended drag');
        onDragEnd && onDragEnd();
      }}
    >
      {children}
    </div>
  );
};

I have the issue that when the drawer closes, the draggable container is lost, and while dropping it works fine, the onDragEnd handler does not get called. How can i retain the onDragEnd event handler?

Ive attached a gif showing the behavior i've described above. After dropping, the drawer should reopen via the onDragEnd() callback.

enter image description here

about 4 years ago · Juan Pablo Isaza
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