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

141
Visualizações
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 à 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