Skip to content

Commit

Permalink
Merge pull request #1413 from flexyford/flexyford/pass-event-on-choose
Browse files Browse the repository at this point in the history
onChange action receives Event as last arg on mouseup
  • Loading branch information
cibernox authored May 1, 2021
2 parents 9053787 + 3b72222 commit 9441083
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions addon/components/power-select/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class Options extends Component<Args> {
if (role === 'group') {
return;
}
let findOptionAndPerform = (action: Function, select: Select, e: Event): void => {
let findOptionAndPerform = (action: Function, e: Event): void => {
if (e.target === null) return;
let optionItem = (e.target as Element).closest('[data-option-index]');
if (!optionItem) {
Expand All @@ -57,12 +57,12 @@ export default class Options extends Component<Args> {
}
let optionIndex = optionItem.getAttribute('data-option-index');
if (optionIndex === null) return;
action(this._optionFromIndex(optionIndex), select, e);
action(this._optionFromIndex(optionIndex), e);
};
this.mouseUpHandler = (e: MouseEvent): void => findOptionAndPerform(this.args.select.actions.choose, this.args.select, e);
this.mouseUpHandler = (e: MouseEvent): void => findOptionAndPerform(this.args.select.actions.choose, e);
element.addEventListener('mouseup', this.mouseUpHandler);
if (this.args.highlightOnHover) {
this.mouseOverHandler = (e: MouseEvent): void => findOptionAndPerform(this.args.select.actions.highlight, this.args.select, e);
this.mouseOverHandler = (e: MouseEvent): void => findOptionAndPerform(this.args.select.actions.highlight, e);
element.addEventListener('mouseover', this.mouseOverHandler);
}
if (this.isTouchDevice) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,13 @@ module('Integration | Component | Ember Power Select (Mouse control)', function(
});

test('Clicking an item selects it, closes the dropdown and focuses the trigger', async function(assert) {
assert.expect(4);
assert.expect(5);

this.numbers = numbers;
this.foo = (val, dropdown) => {
this.foo = (val, dropdown, event) => {
assert.equal(val, 'four', 'The action is invoked with the selected value as first parameter');
assert.ok(dropdown.actions.close, 'The action is invoked with the the dropdown object as second parameter');
assert.ok(event instanceof window.Event, 'The third argument is an event');
};
await render(hbs`
<PowerSelect @options={{numbers}} @onChange={{foo}} as |option|>
Expand Down

0 comments on commit 9441083

Please sign in to comment.