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: 1 addition & 2 deletions src/dom/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,7 @@ function dom(p5, fn) {
* - `mySelect.disable(option)` marks a given option as disabled.
* - `mySelect.enable()` marks the whole dropdown element as enabled.
* - `mySelect.enable(option)` marks a given option as enabled.
* - Enabling a dropdown or an option doesn't change which option is selected.
*
* @method createSelect
* @param {Boolean} [multiple] support multiple selections.
Expand Down Expand Up @@ -1226,14 +1227,12 @@ function dom(p5, fn) {
for (let i = 0; i < this.elt.length; i++) {
if (this.elt[i].value.toString() === value) {
this.elt[i].disabled = false;
this.elt[i].selected = false;
}
}
} else {
this.elt.disabled = false;
for (let i = 0; i < this.elt.length; i++) {
this.elt[i].disabled = false;
this.elt[i].selected = false;
}
}
return this;
Expand Down
25 changes: 25 additions & 0 deletions test/unit/dom/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,31 @@ suite('DOM', function () {
testElement.disable(options[disabledIndex]);
assert.isTrue(testElement.elt.options[disabledIndex].disabled);
assert.isFalse(testElement.elt.options[disabledIndex].selected);
});
test('calling enable() should not change the selected option', function () {
const testElement = mockP5Prototype.createSelect();
const options = ['red', 'yellow', 'blue'];
for (const optionName of options) testElement.option(optionName);

testElement.selected('blue');
testElement.disable();
testElement.enable();

assert.isFalse(testElement.elt.disabled);
assert.equal(testElement.value(), 'blue');
assert.equal(testElement.selected(), 'blue');
});

test('calling enable(option) should not change the selected option', function () {
const testElement = mockP5Prototype.createSelect();
const options = ['red', 'yellow', 'blue'];
for (const optionName of options) testElement.option(optionName);

testElement.selected('blue');
testElement.enable('blue');

assert.isFalse(testElement.elt.options[2].disabled);
assert.equal(testElement.value(), 'blue');
});
});

Expand Down