Skip to content

Commit

Permalink
Fixes HTMLSelectElement.prototype.remove to include `Element.protot…
Browse files Browse the repository at this point in the history
…ype.remove`
  • Loading branch information
mhassan1 authored and JakeChampion committed Apr 11, 2022
1 parent 32a7b12 commit 9a696c2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
11 changes: 11 additions & 0 deletions polyfills/Element/prototype/remove/polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ Document.prototype.remove = Element.prototype.remove = function remove() {
if ("Text" in self) {
Text.prototype.remove = Element.prototype.remove;
}

(function () {
var originalRemove = HTMLSelectElement.prototype.remove;

HTMLSelectElement.prototype.remove = function remove(index) {
if (arguments.length === 0) {
return Element.prototype.remove.call(this);
}
return originalRemove.call(this, index);
};
})();
36 changes: 36 additions & 0 deletions polyfills/Element/prototype/remove/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,39 @@ it('can remove itself from nothing', function () {

proclaim.equal(element.childNodes.length, 0);
});

it('can remove a select', function () {
child.remove();

var select = document.createElement('select');
element.appendChild(select);

proclaim.equal(select.remove(), undefined);

proclaim.equal(element.childNodes.length, 0);
});

it('does not break the ability for a select to remove an option', function () {
child.remove();

var select = document.createElement('select');
var option = document.createElement('option');
element.appendChild(select);
select.appendChild(option);

proclaim.equal(select.remove(0), undefined);

proclaim.equal(select.childNodes.length, 0);
proclaim.equal(element.childNodes.length, 1);
});

it('does not remove a select when passed `undefined`', function () {
child.remove();

var select = document.createElement('select');
element.appendChild(select);

proclaim.equal(select.remove(undefined), undefined);

proclaim.equal(element.childNodes.length, 1);
});

0 comments on commit 9a696c2

Please sign in to comment.