Skip to content

Commit

Permalink
backport kebob-case event names, argument order
Browse files Browse the repository at this point in the history
- see adopted-ember-addons#159
- change event names to kebab-case to smooth transition from 2.x to 3.x
- change argument order to match 3.x
- NOTE: last argument `component` is deprecated in 3.x
  • Loading branch information
kjhangiani committed Dec 7, 2017
1 parent 46dd05f commit 4d00365
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 25 deletions.
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +155,30 @@ export default Ember.Route.extend({
x-select also provides other actions that fire on different event
types. These actions follow the HTML input event naming convention.

**onblur**
**on-blur**

`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.
`on-blur` fires anytime the `blur` event is triggered on the x-select
component. When the action fires it sends three arguments: the value,
the jQuery event, and the component.

**onfocusout**
**on-focus-out**

`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.
`on-focus-out` fires anytime the `focusOut` event is triggered on the x-select
component. When the action fires it sends three arguments: the value,
the jQuery event, and the component.

**onclick**
**on-click**

`onclick` fires when x-select is clicked. When the action fires it
sends three arguments: the component, the value, and the jQuery event.
`on-click` fires when x-select is clicked. When the action fires it
sends three arguments: the value, the jQuery event, and the component.

**on-change**

`on-change` fires when x-select is changed. When the action fires it
sends three arguments: the value, the jQuery event, and the component.

NOTE: For all events, the 3rd argument, the component, is removed in emberx-select 3.x+
This argument remains in emberx-select 2.x for legacy support.

### Test Helpers

Expand Down
8 changes: 4 additions & 4 deletions addon/components/x-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,31 +109,31 @@ export default Ember.Component.extend({
}

this.sendAction('action', nextValue, this);
this.sendAction('onchange', this, nextValue, event);
this.sendAction('on-change', nextValue, event, this);
},

/**
* 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.sendAction('on-click', this._getValue(), event, this);
},

/**
* 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.sendAction('on-blur', this._getValue(), event, this);
},

/**
* 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.sendAction('on-focus-out', this._getValue(), event, this);
},

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/app/controllers/events/blur.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Ember from 'ember';

export default Ember.Controller.extend({
actions: {
onBlur(component, value, event) {
onBlur(value, event/*, component*/) {
this.set('eventType', event.type);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/app/controllers/events/click.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Ember from 'ember';

export default Ember.Controller.extend({
actions: {
onClick(component, value, event) {
onClick(value, event/*, component*/) {
this.set('eventType', event.type);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/app/controllers/events/focus-out.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Ember from 'ember';

export default Ember.Controller.extend({
actions: {
focusOut(component, value, event) {
focusOut(value, event/*, component*/) {
this.set('eventType', event.type);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/app/templates/events/blur.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h2>Blur</h2>

{{#x-select value=it onblur="onBlur"}}
{{#x-select value=it on-blur="onBlur"}}
{{#x-option value=charles}}Charles{{/x-option}}
{{#x-option value=bastion}}Bastion{{/x-option}}
{{#x-option value=stanley}}Stanley{{/x-option}}
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/app/templates/events/click.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h2>Click</h2>

{{#x-select value=it onclick="onClick"}}
{{#x-select value=it on-click="onClick"}}
{{#x-option value=charles}}Charles{{/x-option}}
{{#x-option value=bastion}}Bastion{{/x-option}}
{{#x-option value=stanley}}Stanley{{/x-option}}
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/app/templates/events/focus-out.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h2>Focus Out</h2>

{{#x-select value=it onfocusout="focusOut"}}
{{#x-select value=it on-focus-out="focusOut"}}
{{#x-option value=charles}}Charles{{/x-option}}
{{#x-option value=bastion}}Bastion{{/x-option}}
{{#x-option value=stanley}}Stanley{{/x-option}}
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/components/two-way-data-binding-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ describeComponent(
beforeEach(function() {
this.set('make', 'ford');
this.set('capture', (value)=> this.value = value);
this.set('onClick', (x, value)=> this.click = value);
this.set('onFocusOut', (x, value)=> this.focusOut = value);
this.set('onBlur', (x, value)=> this.blur = value);
this.set('onClick', (value)=> this.click = value);
this.set('onFocusOut', (value)=> this.focusOut = value);
this.set('onBlur', (value)=> this.blur = value);

this.render(hbs`
{{#x-select value=make one-way=true action=capture onclick=onClick onfocusout=onFocusOut onblur=onBlur}}
{{#x-select value=make one-way=true action=capture on-click=onClick on-focus-out=onFocusOut on-blur=onBlur}}
{{#x-option value="ford"}}Ford{{/x-option}}
{{#x-option value="chevy"}}Chevy{{/x-option}}
{{#x-option value="dodge" class="spec-dodge-option"}}Dodge{{/x-option}}
Expand Down

0 comments on commit 4d00365

Please sign in to comment.