Skip to content

extending onContextMenu to return the complete component element and the event #24

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Standard example:

#### onCheck

Returns: `node`
Returns: `node.model`

Fired when a checkbox state changes.

Expand All @@ -55,7 +55,7 @@ Fired when a checkbox state changes.

#### onContextMenu

Returns: `node`
Returns: `node`, `event`

Fired on contextMenu event.

Expand All @@ -65,7 +65,7 @@ Fired on contextMenu event.

#### onHover

Returns: `node`
Returns: `node.model`

Fired when a mouse enters the node.

Expand All @@ -75,7 +75,7 @@ Fired when a mouse enters the node.

#### onHoverOut

Returns: `node`
Returns: `node.model`

Fired when a mouse leaves the node.

Expand All @@ -85,7 +85,7 @@ Fired when a mouse leaves the node.

#### onSelect

Returns: `node`
Returns: `node.model`

Fired when a node is selected.

Expand Down
2 changes: 1 addition & 1 deletion addon/components/x-tree-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default Component.extend({
contextMenu(event) {
if (this.onContextMenu) {
event.preventDefault();
this.onContextMenu(this.model);
this.onContextMenu(this, event);
}
},

Expand Down
6 changes: 5 additions & 1 deletion tests/integration/components/x-tree-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,16 @@ module('Integration | Component | x-tree', function(hooks) {
});

test('contextMenu event', async function(assert) {
this.set('onContextMenu', x => this.name = x.name);
this.set('onContextMenu', (x, event) => {
this.name = x.model.name;
this.targetTagName = event.target.tagName;
});
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');
assert.equal(this.targetTagName, 'SPAN', 'contextMenu event hit a span element');
});
});