Skip to content

Commit

Permalink
Merge pull request #44 from jbailey4/patch-1
Browse files Browse the repository at this point in the history
adds custom didToggle method
  • Loading branch information
samselikoff authored Jun 10, 2018
2 parents 922d971 + aeb6a44 commit dc029f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 8 additions & 1 deletion addon/components/cp-panel/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,17 @@ export default Component.extend({
}
});
},

// Custom action called when toggling that can be provided by caller
didToggle() {},

actions: {
toggleIsOpen() {
this.get('panelActions').toggle(this.get('name'));
let name = this.get('name');

this.get('panelActions').toggle(name);

this.didToggle(name);
}
}
});
14 changes: 14 additions & 0 deletions tests/integration/cp-panel-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,17 @@ test('it can nest panels', function(assert) {
// make sure the childs text is now showing
assert.equal($child.find('.cp-Panel-body').text().match(`Im a Child!`).length, 1);
});

test('it calls custom didToggle method when toggled', function(assert) {
this.set('handleToggle', (panelName) => assert.ok(panelName, `didToggle invoked and passed the panel name: ${panelName}`));

this.render(hbs`
{{#cp-panel didToggle=handleToggle as |p|}}
{{p.toggle}}
{{#p.body}}Hi!{{/p.body}}
{{/cp-panel}}
`);

var $panel = this.$('.cp-Panel');
$panel.find('.cp-Panel-toggle').click();
});

0 comments on commit dc029f8

Please sign in to comment.