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 4 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
5 changes: 4 additions & 1 deletion addon/components/power-select-multiple/trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ export default Component.extend({
}),

maybePlaceholder: computed('placeholder', 'select.selected.length', function() {
if (isIE) {
let component = this.get('placeholderComponent');
let hasCustomPlaceholder = component !== 'power-select/placeholder';
Copy link
Owner

Choose a reason for hiding this comment

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

Since you are not going to render this placeholder if the search is disabled, I think that you don't need this code.


if (isIE || hasCustomPlaceholder) {
return null;
}
let select = this.get('select');
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-eq placeholder maybePlaceholder)}}
Copy link
Owner

Choose a reason for hiding this comment

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

This is changing the logic and concerns me.
Originally the placeholder only shows if the search was not enabled but if I'm reading this right in here it's going to show even if there is a search input. Am I wrong?

Copy link
Author

Choose a reason for hiding this comment

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

no you are right, i just realized this myself and am correcting it :) thx for the review

{{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
25 changes: 24 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,27 @@ 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"
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.'
);
});