-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
Increasing Access
Better documenting the confusing behavior of <select> / <option> can help beginners new to coding avoid gotchas that can lead to frustration.
Most appropriate sub-area of p5.js?
- Accessibility
- Color
- Core/Environment/Rendering
- Data
- DOM
- Events
- Image
- IO
- Math
- Typography
- Utilities
- WebGL
- Build Process
- Unit Testing
- Internalization
- Friendly Errors
- Other (specify if possible)
Feature enhancement details
See #1969 (comment) for an in-depth contextual explanation of a lack of unique <option> element text contents leading to undefined and causing a confusing situation for a student.
We should more clearly document that <option> text contents are expected to be unique--when .option(optionName) is called with non-unique values, rather than new options being added as expected, existing options' values are set to undefined.
A minimal example is:
function setup() {
const select = createSelect();
select.option("a");
select.option("a");
}Here, one might expect a dropdown with two "a" elements, but instead, one <option> is created with value="undefined" rather than value="a":
<select>
<option value="undefined">a</option>
</select>Contrast this to comparable native DOM code:
const select = document.createElement("select");
document.body.appendChild(select);
const option0 = document.createElement("option");
option0.textContent = option0.value = "a";
const option1 = document.createElement("option");
option1.textContent = option1.value = "a";
select.append(option0, option1);Which creates the unsurprising:
<select>
<option value="a">a</option>
<option value="a">a</option>
</select>