Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
emberx-select
Advanced tools
A Select component based on the native html select.
We've tried other select components, and were missing the reliability,
maintainability, and accessbility of the native html <select>
.
<x-select>
is a drop-in component to let you use any
object for your selectable options. You can use it out of the box, or
as a building block of something more ambitious.
The goal of <x-select>
is to let you see how it works and style it
right in your template, rather than passing in a ball of configuration
or wrapping a hard-coded, inaccessible jQuery plugin.
ember install emberx-select
By allowing arbitrary html to appear in the template of the select
element, you can use it just like you would normally. This means
things like having <optgroup>
tags inside your select, or even plain
old <option>
elements to represent things like empty values.
XSelect thinly wraps a native <select>
element so that it can be object
and binding aware. It is used in conjuction with the x-option
component to construct select boxes. E.g.
{{#x-select value=bob action="selectPerson"}}
{{#x-option value=fred}}Fred Flintstone{{/x-option}}
{{#x-option value=bob}}Bob Newhart{{/x-option}}
{{/x-select}}
the options are always up to date, so that when the object bound to
value
changes, the corresponding option becomes selected.
Whenever the select tag receives a change event, it will fire
action
.
If you're just changing a model's property, you don't need action
. For example,
if you have a model with a status
field with an integer, you can do this:
{{#x-select value=model.status }}
{{#x-option value=1}}Active{{/x-option}}
{{#x-option value=2}}Inactive{{/x-option}}
{{/x-select}}
As of version 2.1.0, emberx-select
takes advantage of Ember's
contextual components
feature. Using contextual components allows emberx-select
to skip some
potentially expensive DOM traversals. This feature works with Ember
2.3.0 and above! If you're using such a version, we highly recommend
you use it:
{{#x-select value=model.status as |xs|}}
{{#xs.option value=1}}Active{{/xs.option}}
{{#xs.option value=2}}Inactive{{/xs.option}}
{{/x-select}}
If you're using a lower version of Ember, emberx-select
will continue
to work without block params for the forseeable future.
As of version 1.1.0, emberx-select
supports the multiple
option. This means you can pass an array as its value, and it will set
its selections directly on that array.
{{#x-select value=selections multiple=true action="selectionsChanged"}}
{{#x-option value=fred}}Fred Flintstone{{/x-option}}
{{#x-option value=bob}}Bob Newhart{{/x-option}}
{{#x-option value=andrew}}Andrew WK{{/x-option}}
{{/x-select}}
The selections array will be initialized to an empty array if not present.
In x-select v2.2.0 we introduced a way to disable two way data
binding, which is enabled by default. If you would like to only mutate
the value of x-select through actions you can pass an attribute called
one-way
and set it to true
. This will disable two way data binding.
{{#x-select value=willNotChangeOnSelection one-way=true}}
{{#x-option value="hello" selected=true}}Hello{{/x-option}}
{{#x-option value="world"}}World{{/x-option}}
{{/x-select}}
If you select the World
option in the example above, it will not
change the value (willNotChangeOnSelection
) to world
. Without
one-way=true
it would change the value.
The action that is dispatched by x-select whenever the selected value or values change (change event) has a function signature of:
/**
* @param value {Object} the value selected by the user.
* @param component {Ember.Component} the x-select component itself
*/
function (value, component) {
// action body...
}
Most of the time all you need is the value that has been selected, but sometimes your action requires more context than just that. In those cases, you can associate arbitrary attributes with the component itself and use them later inside your action handler. For example:
{{#x-select action="didMakeSelection" default=anything}}
<option>Nothing</option>
{{#x-option value=something}}Something{{/x-option}}
{{/x-select}}
then, inside your action handler:
export default Ember.Route.extend({
actions: {
didMakeSelection: function(selection, component) {
if (selection) {
this.set('selection', selection)
} else {
this.set('selection', component.get('default'))
}
}
}
});
x-select also provides other actions that fire on different event types. These actions follow the HTML input event naming convention.
onblur
onblur
fires anytime the blur
event is triggered on the x-select
component. When the action fires it sends three arguments: the
component, the value, and the jQuery event.
onfocusout
onfocusout
fires anytime the focusOut
event is triggered on the x-select
component. When the action fires it sends three arguments: the
component, the value, and the jQuery event.
onclick
onclick
fires when x-select is clicked. When the action fires it
sends three arguments: the component, the value, and the jQuery event.
Since emberx-select
uses internal identifiers as the value
attribute, it
doesn't integrate with the fillIn
test helper. But don't fret, we've automatically
injected the test helper into your app.
As of version 1.1.3 we support both multiselects and regular selects. To use, you need to specify the class on the select as the first argument and the rest of the arguments are the options you'd like to select. For example:
//... Single select
select('.my-drop-down', 'My Option');
//...
Multiselect
//... Multiselect
select('.my-drop-down', 'My Option', 'My Option Two', 'My Option Three');
//...
You need to run the generator: ember g emberx-select
You need to either run the generator (ember g emberx-select
) or import the test helper into your
test-helper.js
file:
import registerSelectHelper from './helpers/register-select-helper';
registerSelectHelper();
emberx-select is part of the "missing components of ember" collectively known as emberx:
ember test
ember test --server
Please note that this project is released with a Contributor Code of
Conduct. By participating in this project you agree to abide by its
terms, which can be found in the CODE_OF_CONDUCT.md
file in this
repository.
v2.2.3 (2016-12-27)
Closed issues:
Merged pull requests:
Ember.K
usage with JavaScript syntax #165 (locks)options
arrays between x-select instances #150 (fivetanley)FAQs
A Select component based on html select.
The npm package emberx-select receives a total of 602 weekly downloads. As such, emberx-select popularity was classified as not popular.
We found that emberx-select demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.