JSFiddle - React, Tailwind, and code Playground
HTML
<div id="draggable">Drag this to the list <a class="remove" onclick="removeItem($(this).parent())" href="javascript:void(0)">X</a></div>
<div id="sortable">
<div class="placeholder">Drop elements here</div>
</div>
CSS
.placeholder {
opacity: 0.5;
}
#draggable .remove {
display: none;
}
JavaScript
function updatePlaceholder () {
var $list = $(this);
var count = $list.children(':not(.placeholder)').length;
$list.children('.placeholder').css("display", count > 0 ? "none" : "block");
}
function removeItem ($item) {
var $list = $item.parent();
$item.remove();
updatePlaceholder.call($list[0]);
}
$(document).ready(function () {
$("#sortable").sortable({
revert: true,
over: updatePlaceholder,
out: updatePlaceholder,
stop: updatePlaceholder
});
$("#draggable").draggable({
connectToSortable: "#sortable",
helper: "clone",
revert: "invalid",
stop: function () {
updatePlaceholder.call($("#sortable")[0]);
}
});
});