Skip to content
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

Add support for contextMenu event #23

Merged
merged 5 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ Fired when a node is selected.
{{x-tree model=tree onSelect=(action 'onSelect')}}
```

#### onContextMenu

Returns: `node`

Fired on contextMenu event.

```handlebars
{{x-tree model=tree onContextMenu=(action 'onContextMenu')}}
```

### Available options

#### checkable
Expand Down
7 changes: 7 additions & 0 deletions addon/components/x-tree-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ export default Component.extend({
return get(this, 'model.id') === this.chosenId;
}),

contextMenu(e) {
if (this.onContextMenu) {
e.preventDefault();
this.onContextMenu(this.model)
}
},

click() {
if (this.onSelect && !get(this, 'model.isDisabled')) {
let wasChecked = get(this, 'model.isChecked');
Expand Down
2 changes: 2 additions & 0 deletions addon/templates/components/x-tree-branch.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
chosenId=chosenId
onCheck=onCheck
onSelect=onSelect
onContextMenu=onContextMenu
onHover=onHover
onHoverOut=onHoverOut
model=child
Expand All @@ -26,6 +27,7 @@
chosenId=chosenId
onCheck=onCheck
onSelect=onSelect
onContextMenu=onContextMenu
onHover=onHover
onHoverOut=onHoverOut
expandedIcon=expandedIcon
Expand Down
4 changes: 4 additions & 0 deletions addon/templates/components/x-tree-children.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
chosenId=chosenId
onCheck=onCheck
onSelect=onSelect
onContextMenu=onContextMenu
onHover=onHover
onHoverOut=onHoverOut
model=model
Expand All @@ -24,6 +25,7 @@
chosenId=chosenId
onCheck=onCheck
onSelect=onSelect
onContextMenu=onContextMenu
onHover=onHover
onHoverOut=onHoverOut
model=model.children
Expand All @@ -43,6 +45,7 @@
chosenId=chosenId
onCheck=onCheck
onSelect=onSelect
onContextMenu=onContextMenu
onHover=onHover
onHoverOut=onHoverOut
expandedIcon=expandedIcon
Expand All @@ -57,6 +60,7 @@
chosenId=chosenId
onCheck=onCheck
onSelect=onSelect
onContextMenu=onContextMenu
onHover=onHover
onHoverOut=onHoverOut
expandedIcon=expandedIcon
Expand Down
2 changes: 2 additions & 0 deletions addon/templates/components/x-tree.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
chosenId=chosenId
onCheck=onCheck
onSelect=onSelect
onContextMenu=onContextMenu
onHover=onHover
onHoverOut=onHoverOut
model=model
Expand All @@ -22,6 +23,7 @@
chosenId=chosenId
onCheck=onCheck
onSelect=onSelect
onContextMenu=onContextMenu
onHover=onHover
onHoverOut=onHoverOut
expandedIcon=expandedIcon
Expand Down
16 changes: 15 additions & 1 deletion tests/integration/components/x-tree-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { module, test } from 'qunit';
import { set } from '@ember/object';
import { setupRenderingTest } from 'ember-qunit';
import { render, find, findAll, click } from '@ember/test-helpers';
import { render, find, findAll, click, triggerEvent } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import Component from '@ember/component';

Expand Down Expand Up @@ -241,4 +241,18 @@ module('Integration | Component | x-tree', function(hooks) {
await click('.tree-node span');
assert.equal(this.selected, false, 're-enabled tree nodes can be selected again');
});

test('contextmenu event', async function(assert) {
this.set('onContextMenu', (item) => {
this.name = item.name;
});
this.set('tree', standardTree);

await render(hbs`{{x-tree model=tree onContextMenu=onContextMenu}}`);
await triggerEvent('.tree-node span', 'contextmenu')

assert.equal(this.name, 'Root', 'item from contextmenu event is returned as expected');

});

});