Ошибка при удалении элемента
Я создаю div с input поверх Canvas для изменения размеров.Ошибка вылазит если я начал выделять текст в input, а отпустил кнопку за пределами Input,но в пределах wrap.Искал решение проблемы, предложили через parentNode.removeChild, но мне не помогло. Как сделать чтоб не было этой ошибки, при поведении, что начал выделять в input, а отпустил мышку за пределами input, но в пределах wrap.
сама ошибка
Failed to execute 'removeChild' on 'Node': The node to be removed is no longer a child of this node. Perhaps it was moved in a 'blur' event handler?
Функция создания и удаления input
function createInput(pos, value, item) {
const containerDiv = document.getElementById('container');
var wrap = document.createElement('div');
wrap.style.position = 'absolute';
wrap.style.top = 0;
wrap.style.left = 0;
wrap.style.width = '100%';
wrap.style.height = '100%';
containerDiv.appendChild(wrap)
const input = document.createElement('input');
input.type = 'number';
input.style.position = 'absolute';
input.style.top = pos.y + 3 + 'px';
input.style.left = pos.x + 'px';
input.style.height = 20 + 3 + 'px';
input.style.width = 100 + 3 + 'px';
input.value = (value + 2) * 5
if (item.derection === 2) {
input.onblur = (e) => dispatch(onBlurInputHorizontal({ value: e.currentTarget?.value / 5, containerDiv, wrap, itemSelect: item, width: item.width }))
}
else {
input.onblur = (e) => dispatch(onBlurInputVertical({ value: e.currentTarget?.value / 5, containerDiv, wrap, itemSelect: item, height: item.height }))
}
wrap.appendChild(input);
function removeInput(e) {
if (e.target === wrap) {
wrap.parentNode.removeChild(wrap);
wrap.removeEventListener("click", removeInput);
}
}
wrap.addEventListener('click', removeInput, { once: true });
}