-
-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update actions to kebob case & arguments. #159
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,18 +36,18 @@ export default Ember.Component.extend({ | |
* | ||
* @property disabled | ||
* @type Boolean | ||
* @default null | ||
* @default false | ||
*/ | ||
disabled: null, | ||
disabled: false, | ||
|
||
/** | ||
* Bound to the `multiple` attribute on the native <select> tag. | ||
* | ||
* @property multiple | ||
* @type Boolean | ||
* @default null | ||
* @default false | ||
*/ | ||
multiple: null, | ||
multiple: false, | ||
|
||
/** | ||
* The collection of options for this select box. When options are | ||
|
@@ -71,39 +71,91 @@ export default Ember.Component.extend({ | |
*/ | ||
tabindex: 0, | ||
|
||
/** | ||
* Function for the `on-blur` action | ||
* | ||
* @property on-blur | ||
* @type Function | ||
*/ | ||
"on-blur": Ember.K, | ||
|
||
/** | ||
* Function for the `on-click` action | ||
* | ||
* @property on-click | ||
* @type Function | ||
*/ | ||
"on-click": Ember.K, | ||
|
||
/** | ||
* Function for the `on-change` action | ||
* | ||
* @property on-change | ||
* @type Function | ||
*/ | ||
"on-change": Ember.K, | ||
|
||
/** | ||
* Function for the `on-focus-out` action | ||
* | ||
* @property on-focus-out | ||
* @type Function | ||
*/ | ||
"on-focus-out": Ember.K, | ||
|
||
/** | ||
* Function that calls an action and sends the proper arguments. | ||
* | ||
* @method _handleAction | ||
* @type Function | ||
* @param {String} action - string name of the action to invoke | ||
* @param {String|Object} value - current value of the component | ||
* @param {Object} event - jQuery event from the current action | ||
*/ | ||
_handleAction(action, value, event) { | ||
let actionValue = this.get(action); | ||
|
||
if(typeof actionValue === 'string') { | ||
Ember.warn(`x-select: You must use the action helper for all actions. The try: ${action}=(action "${actionValue}") in your template`, false, {id: 'x-select-string-action'}); | ||
return; | ||
} | ||
|
||
this.get(action)(value, event); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the right track, but I think we can make it a bit clearer and improve the error handling even more.
actionValue(value, event); |
||
}, | ||
|
||
/** | ||
* When the select DOM event fires on the element, trigger the | ||
* component's action with the current value. | ||
*/ | ||
change(event) { | ||
let nextValue = this._getValue(); | ||
|
||
this.sendAction('action', nextValue, this); | ||
this.sendAction('onchange', this, nextValue, event); | ||
this.sendAction('action', nextValue, event, this); | ||
this._handleAction('on-change', nextValue, event); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this dispatch correctly? I'm concerned that bubbling an action with |
||
}, | ||
|
||
/** | ||
* When the click DOM event fires on the element, trigger the | ||
* component's action with the component, x-select value, and the jQuery event. | ||
*/ | ||
click(event) { | ||
this.sendAction('onclick', this, this._getValue(), event); | ||
this._handleAction('on-click', this._getValue(), event); | ||
}, | ||
|
||
/** | ||
* When the blur DOM event fires on the element, trigger the | ||
* component's action with the component, x-select value, and the jQuery event. | ||
*/ | ||
blur(event) { | ||
this.sendAction('onblur', this, this._getValue(), event); | ||
this._handleAction('on-blur', this._getValue(), event); | ||
}, | ||
|
||
/** | ||
* When the focusOut DOM event fires on the element, trigger the | ||
* component's action with the component, x-select value, and the jQuery event. | ||
*/ | ||
focusOut(event) { | ||
this.sendAction('onfocusout', this, this._getValue(), event); | ||
this._handleAction('on-focus-out', this._getValue(), event); | ||
}, | ||
|
||
/** | ||
|
@@ -125,7 +177,7 @@ export default Ember.Component.extend({ | |
* | ||
* @private | ||
* @return {Array} all the values from selected x-options | ||
*/ | ||
*/ | ||
_findMultipleValues() { | ||
return this.get('options').filter(isSelectedOption).map(option => option.get('value')); | ||
}, | ||
|
@@ -136,7 +188,7 @@ export default Ember.Component.extend({ | |
* | ||
* @private | ||
* @return {Object} the value of the first select `x-option`, or null | ||
*/ | ||
*/ | ||
_findSingleValue() { | ||
let selectedValue = this.get('options').find(isSelectedOption); | ||
return selectedValue ? selectedValue.get('value') : null; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* jshint expr:true */ | ||
import { expect } from 'chai'; | ||
import { describeComponent, it } from 'ember-mocha'; | ||
import { describe, beforeEach } from 'mocha'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
|
||
describeComponent( | ||
'default-value', | ||
'Integration: DefaultValue', | ||
{ | ||
integration: true | ||
}, | ||
function() { | ||
describe("default value of null", function() { | ||
beforeEach(function() { | ||
this.set('make', null); | ||
this.set('selectAction', (value) => { | ||
this.set("make", value); | ||
this.set("wasCalled", true); | ||
}); | ||
|
||
this.render(hbs` | ||
{{#x-select value=make action=selectAction as |xs|}} | ||
{{#xs.option value="fordValue" class="spec-ford-option"}}Ford{{/xs.option}} | ||
{{#xs.option value="chevyValue"}}Chevy{{/xs.option}} | ||
{{#xs.option value="dodgeValue" class="spec-dodge-option"}}Dodge{{/xs.option}} | ||
{{/x-select}} | ||
`); | ||
}); | ||
|
||
it("displays the first item in the list", function() { | ||
expect(this.$('select option:selected').text()).to.equal("Ford"); | ||
}); | ||
|
||
it("sets the default value to the first element", function() { | ||
expect(this.get('make')).to.equal("fordValue"); | ||
}); | ||
|
||
it("invokes the select action on init", function() { | ||
expect(this.get("wasCalled")).to.equal(true); | ||
}); | ||
|
||
}); | ||
} | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a typo?