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 extra params for selectedItemComponent on trigger (power-select-multiple) #1111

Merged
merged 3 commits into from
May 9, 2018
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
4 changes: 2 additions & 2 deletions addon/templates/components/power-select-multiple/trigger.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</span>
{{/unless}}
{{#if selectedItemComponent}}
{{component selectedItemComponent option=(readonly opt) select=(readonly select)}}
{{component selectedItemComponent extra=(readonly extra) option=(readonly opt) select=(readonly select)}}
{{else}}
{{yield opt select}}
{{/if}}
Expand All @@ -36,4 +36,4 @@
onkeydown={{action "onKeydown"}}>
{{/if}}
</ul>
<span class="ember-power-select-status-icon"></span>
<span class="ember-power-select-status-icon"></span>
4 changes: 2 additions & 2 deletions tests/dummy/app/templates/components/selected-country.hbs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<img src="{{select.selected.flagUrl}}" class="icon-flag" alt="Flag of {{select.selected.name}}">
{{select.selected.name}}
<img src="{{select.selected.flagUrl}}" class="icon-flag {{if extra.coolFlagIcon 'cool-flag-icon'}}" alt="Flag of {{select.selected.name}}">
{{select.selected.name}}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<img src="{{select.selected.flagUrl}}" class="icon-flag" alt="Flag of {{select.selected.name}}">
{{select.selected.name}}
<img src="{{select.selected.flagUrl}}" class="icon-flag {{if extra.coolFlagIcon 'cool-flag-icon'}}" alt="Flag of {{select.selected.name}}">
{{select.selected.name}}
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,61 @@ module('Integration | Component | Ember Power Select (Customization using compon

await clickTrigger();
});

test('the power-select-multiple `optionsComponent` receives the `extra` hash', async function(assert) {
assert.expect(2);

this.countries = countries;
this.country = countries[1]; // Spain

await render(hbs`
{{#power-select-multiple options=countries selected=country optionsComponent="list-of-countries" onchange=(action (mut foo)) extra=(hash field='code') as |country|}}
{{country.code}}
{{/power-select-multiple}}
`);

await clickTrigger();

assert.dom('.ember-power-select-options').includesText('Countries:', 'The given component is rendered');
assert.dom('.ember-power-select-options').includesText('3. RU', 'The component uses the field option in the `extra` hash to render the options');
});

test('the power-select-multiple `triggerComponent` receives the `extra` hash', async function(assert) {
assert.expect(1);

this.countries = countries;
this.country = countries[1]; // Spain

await render(hbs`
{{#power-select-multiple options=countries selected=country triggerComponent="selected-country" onchange=(action (mut foo)) extra=(hash coolFlagIcon=true) as |country|}}
{{country.code}}
{{/power-select-multiple}}
`);

await clickTrigger();

assert.dom('.ember-power-select-trigger .cool-flag-icon').exists({ count: 1 }, 'The custom triggerComponent renders with the extra.coolFlagIcon customization option triggering some state change.');
});

test('the power-select-multiple `selectedItemComponent` receives the `extra` hash', async function(assert) {
assert.expect(1);

this.countries = countries;
this.country = [countries[1]]; // Spain

await render(hbs`
<div class="select-box">
{{#power-select-multiple
options=countries
selected=country
selectedItemComponent="selected-item-country"
onchange=(action (mut selected))
extra=(hash coolFlagIcon=true) as |country|}}
{{country.code}}
{{/power-select-multiple}}
</div>
`);

assert.dom('.ember-power-select-trigger .cool-flag-icon').exists({ count: 1 }, 'The custom selectedItemComponent renders with the extra.coolFlagIcon customization option triggering some state change.');
});
});