Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/dom/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
22 changes: 22 additions & 0 deletions test/unit/dom/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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
Expand Down