diff --git a/src/dom/dom.js b/src/dom/dom.js index 82276febbc..555597b7a9 100644 --- a/src/dom/dom.js +++ b/src/dom/dom.js @@ -1487,6 +1487,9 @@ function dom(p5, fn) { }; self.remove = function (value) { + if (arguments.length === 0 || value === undefined) { + return Element.prototype.remove.call(this); + } for (const optionEl of self._getOptionsArray()) { if (optionEl.value === value) { if (isLabelElement(optionEl.parentElement)) { diff --git a/test/unit/dom/dom.js b/test/unit/dom/dom.js index 4469096e84..d40cb84eee 100644 --- a/test/unit/dom/dom.js +++ b/test/unit/dom/dom.js @@ -819,6 +819,17 @@ suite('DOM', function () { assert.deepEqual(options, remainingOptions); }); + test('calling remove() without arguments should remove radio element from DOM and _elements', function () { + const radio = mockP5Prototype.createRadio(); + assert.isTrue(document.body.contains(radio.elt)); + assert.isTrue(mockP5Prototype._elements.includes(radio)); + + radio.remove(); + + assert.isFalse(document.body.contains(radio.elt)); + assert.isFalse(mockP5Prototype._elements.includes(radio)); + }); + test('calling value() should return selected value', function () { const options = ['Monday', 'Friday', 'Saturday', 'Sunday']; const selectedValue = options[1]; @@ -1065,6 +1076,17 @@ suite('DOM', function () { const remainingElement = document.body.children[0]; assert.instanceOf(remainingElement, HTMLCanvasElement); }); + + test('removeElements() removes createRadio element from DOM and _elements', function () { + const radio = mockP5Prototype.createRadio(); + assert.isTrue(document.body.contains(radio.elt)); + assert.isTrue(mockP5Prototype._elements.includes(radio)); + + mockP5Prototype.removeElements(); + + assert.isFalse(document.body.contains(radio.elt)); + assert.isFalse(mockP5Prototype._elements.includes(radio)); + }); }); // p5.Element.prototype.addClass