Skip to content

Instantly share code, notes, and snippets.

@bndw
Created October 29, 2015 22:07
Show Gist options
  • Save bndw/861c0ad852fafb178cb7 to your computer and use it in GitHub Desktop.
Save bndw/861c0ad852fafb178cb7 to your computer and use it in GitHub Desktop.
ember select-box component
import Ember from "ember";
export default Ember.Component.extend({
content: null,
selectedValue: null,
didInitAttrs(attrs) {
this._super(...arguments);
if (!this.get('content')) {
this.set('content', []);
}
},
actions: {
change() {
const selectedEl = this.$('select')[0];
const selectedIndex = selectedEl.selectedIndex;
const content = this.get('content');
const selected = content[selectedIndex];
this.set('selectedValue', selected.value);
}
}
});
{{#if label}}
<label>{{label}}</label>
{{/if}}
<select {{action 'change' on='change'}}>
{{#each content key="@index" as |item|}}
<option value="{{item.value}}" selected={{is-equal item selectedValue}}>
{{item.text}}
</option>
{{/each}}
</select>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment