modern <select>. (WIP)
var Select = require('select');
var select = Select()
.label('Select a language')
.multiple()
.add('Javascript')
.add('Google Go')
.add('Bash')
.add('Ruby')
.add('Lua')
.add('C++')
.add('C', 200)
.select('Jasvascript')
.select('Google Go')
.deselect('Google Go')
.select('c');
document.body.appendChild(select.el);
select.on('change', function(){
console.log(select.values());
// => ['javascript', 200]
});
Install with component(1):
$ component install yields/select
Initialize a new Select
.
Unbind internal events.
Set the label.
Allow multiple selections.
Allow search.
Add an option with name
and optional value
.
An option el
can be given, this can be either html
string
or native Element
.
add('js', 0, '<li><img src="js.jpg">Javascript')
Remove an option with name
.
Remove all options.
Select an option with name
.
De-select name
.
Focus <input>
.
Blur <input>
.
Highlight an option by name
.
When an option is in "highlight" mode, it will be selected when the user hits enter.
De-highlight "highlight"ed option
Get an option with name
.
Show the dropdown or option name
.
Hide the dropdown or option name
.
Check if option name
or dropdown are visible.
Toggle .show([name])
, .hide([name])
.
Disable an option name
.
Enable an option name
.
Get / set selected options.
Get selected values.
Search options with term
, if there are listeners for search
event, the .search()
method will do nothing.
this allows you to set up custom search.
var select = Select()
.add('one')
.add('two')
.on('search', function(term){
ajax(term, function(opts){
opts.forEach(select.add, select);
select.highlight(opts[0].name);
})
})
Emitted when you add an option
with an object:
{
name: <lowercase option name>
value: <the option value>
el: <the element>
selected: <true if the option is selected>
}
Emitted when an option is removed, option
object is given as an argument.
Emitted when an option is selected.
{
name: <lowercase option name>
value: <the option value>
el: <the element>
selected: <true if the option is selected>
}
Emitted with Select
instance.
Emitted with an option
object.
Emitted when the select dropdown is shown.
Emitted when the select dropdown is hidden.
Emitted when .search(term)
is called, if there are listeners
the method .search(term)
will do nothing.
Emitted after a search was performed with number of matches.
$ make test
MIT