addon/components/ui-dropdown-menu.js

  1. import layout from '../templates/components/ui-dropdown-menu';
  2. import Component from '@ember/component';
  3.  
  4. /**
  5. ui-dropdown-menu component
  6.  
  7. @module components
  8. @namespace components
  9. @class UiDropdownMenu
  10. @constructor
  11. */
  12. export default Component.extend({
  13. layout: layout,
  14. /**
  15. * the component style class
  16. *
  17. * @property {String} theme
  18. * @default ''
  19. */
  20. theme: '',
  21. /**
  22. * the component style class
  23. *
  24. * @property {String} class
  25. */
  26. class: '',
  27. classNameBindings: ['_uiClass', 'class', 'theme', '_componentClass'],
  28. _uiClass: 'ui',
  29. _componentClass: 'dropdown',
  30. didInsertElement() {
  31. this.renderDropDown();
  32. },
  33. renderDropDown() {
  34. let that = this;
  35. this.$().dropdown({
  36. onChange(value){
  37. if(that.attrs.value){
  38. that.attrs.value.update(value);
  39. }
  40. }
  41. });
  42. },
  43. didRender(){
  44. // re render component then restore default texts
  45. if(!this.attrs.value.value){
  46. this.$().dropdown('restore defaults');
  47. }
  48. }
  49. });