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

Placeholder component for power select multiple #817

Open
wants to merge 7 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Master
- [ENHANCEMENT] Providing a custom `placeholderComponent` is available for
`power-select-multiple` too now.

# 1.5.0-beta.0
- [ENHANCEMENT/BREAKING-ISH] `ember-basic-dropdown` has improved the experience with A11y
Expand Down
2 changes: 2 additions & 0 deletions addon/templates/components/power-select-multiple.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
options=options
optionsComponent=optionsComponent
placeholder=placeholder
placeholderComponent=placeholderComponent
registerAPI=(readonly registerAPI)
renderInPlace=renderInPlace
required=required
Expand Down Expand Up @@ -86,6 +87,7 @@
options=options
optionsComponent=optionsComponent
placeholder=placeholder
placeholderComponent=placeholderComponent
registerAPI=(readonly registerAPI)
renderInPlace=renderInPlace
required=required
Expand Down
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 @@ -16,8 +16,8 @@
{{/if}}
</li>
{{else}}
{{#if (and placeholder (not searchEnabled))}}
<span class="ember-power-select-placeholder">{{placeholder}}</span>
{{#if (not searchEnabled)}}
{{component placeholderComponent placeholder=placeholder}}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last comment. The way the placeholder component works in the single component is that you render it, and it already check if its placeholder property is there to decide wether it renders anything or not.

In think that you simplify this to

{{#if (not searchEnabled)}}
  {{component placeholderComponent placeholder=placeholder}}
{{/if}}

{{/if}}
{{/each}}
{{#if searchEnabled}}
Expand Down
26 changes: 25 additions & 1 deletion tests/integration/components/power-select/multiple-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,4 +809,28 @@ test('If the options of a multiple select implement `isEqual`, that option is us
assert.equal($('.ember-power-select-option:eq(0)').attr('aria-selected'), 'true', 'The item in the list is marked as selected');
nativeMouseUp('.ember-power-select-option:eq(0)'); // select the same user again should remove it
assert.equal(this.$('.ember-power-select-multiple-option').length, 0);
});
});

test('placeholder can be customized using placeholderComponent', function(assert) {
assert.expect(2);

this.countries = countries;

this.render(hbs`
{{#power-select-multiple
options=countries
placeholder="test"
searchEnabled=false
placeholderComponent="custom-placeholder"
onchange=(action (mut foo)) as |country|}}
{{country.name}}
{{/power-select-multiple}}
`);

assert.equal($('.ember-power-select-placeholder').length, 1, 'The placeholder appears.');
assert.equal(
$('.ember-power-select-placeholder').text().trim(),
'This is a very bold placeholder',
'The placeholder content is equal.'
);
});