Creates a dropdown menu <select></select>
element.
The parameter is optional. If true
is passed, as in let mySelect = createSelect(true)
, then the dropdown will support multiple selections. If an existing <select></select>
element is passed, as in let mySelect = createSelect(otherSelect)
, the existing element will be wrapped in a new p5.Element object.
Dropdowns extend the p5.Element class with a few helpful methods for managing options:
mySelect.option(name, [value])
adds an option to the menu. The first paremeter,name
, is a string that sets the option's name and value. The second parameter,value
, is optional. If provided, it sets the value that corresponds to the keyname
. If an option withname
already exists, its value is changed tovalue
.mySelect.value()
returns the currently-selected option's value.mySelect.selected()
returns the currently-selected option.mySelect.selected(option)
selects the given option by default.mySelect.disable()
marks the whole dropdown element as disabled.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.
Examples
Syntax
createSelect([multiple])
createSelect(existing)
Parameters
multiple
Boolean:
support multiple selections.
existing
Object:
select element to wrap, either as a p5.Element or a HTMLSelectElement.
Notice any errors or typos? Please let us know. Please feel free to edit src/dom/dom.js and open a pull request!