Skip to content
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
5 changes: 5 additions & 0 deletions packages/oss-components/src/components/o-s-s/power-select.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
>
<div class="upf-power-select__array-container" role="button" {{on "click" this.toggleDropdown}}>
<div class="array-input-container {{this.inputBorderStateClass}} fx-row padding-px-6 {{if this.isOpen 'active'}}">
{{#if (has-block "prefix")}}
{{yield to="prefix"}}
{{/if}}
<div class="fx-row fx-xalign-center fx-1 padding-left-px-6 padding-right-px-24 fx-gap-px-6 fx-wrap">
{{#each @selectedItems as |selectedItem index|}}
{{yield selectedItem index to="selected-item"}}
Expand Down Expand Up @@ -36,6 +39,7 @@
<OSS::InfiniteSelect
@items={{@items}}
@onSearch={{@onSearch}}
@searchEnabled={{@searchEnabled}}
@inline={{false}}
@onSelect={{this.onSelect}}
@searchPlaceholder={{@searchPlaceholder}}
Expand All @@ -59,6 +63,7 @@
<OSS::InfiniteSelect
@items={{@items}}
@onSearch={{@onSearch}}
@searchEnabled={{@searchEnabled}}
@inline={{false}}
@onSelect={{this.onSelect}}
@searchPlaceholder={{@searchPlaceholder}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const FAKE_SELECTED_ITEMS = ['The Mandalorian'];
const Template = (args) => ({
template: hbs`
<div style="display: flex; justify-content: center; background-color: white; border-radius: 4px">
<OSS::PowerSelect class='padding-sm' @selectedItems={{this.selectedItems}} @items={{this.items}}
<OSS::PowerSelect class='padding-sm' @selectedItems={{this.selectedItems}} @items={{this.items}} @searchEnabled={{this.searchEnabled}}
@onSearch={{this.onSearch}} @onChange={{this.onChange}} @loading={{this.loading}}
@borderless={{this.borderless}} @hasError={{this.hasError}} @feedbackMessage={{this.feedbackMessage}}
@loadingMore={{this.loadingMore}} @placeholder={{this.placeholder}} @searchPlaceholder={{this.searchPlaceholder}}
Expand All @@ -26,6 +26,29 @@ const Template = (args) => ({
context: args
});

const PrefixTemplate = (args) => ({
template: hbs`
<div style="display: flex; justify-content: center; background-color: white; border-radius: 4px">
<OSS::PowerSelect class='padding-sm' @selectedItems={{this.selectedItems}} @items={{this.items}}
@onSearch={{this.onSearch}} @onChange={{this.onChange}} @loading={{this.loading}}
@borderless={{this.borderless}} @hasError={{this.hasError}} @feedbackMessage={{this.feedbackMessage}}
@loadingMore={{this.loadingMore}} @placeholder={{this.placeholder}} @searchPlaceholder={{this.searchPlaceholder}}
@onBottomReached={{this.onBottomReached}} @addressableAs={{this.addressableAs}}>
<:prefix>
<OSS::Icon @icon="fa-grid-2-plus" />
</:prefix>
Comment thread
Elodie-DeMatteis-Upf marked this conversation as resolved.
Resolved
<:selected-item as |selectedItem|>
{{selectedItem}}
</:selected-item>
<:option-item as |item|>
{{item}}
</:option-item>
</OSS::PowerSelect>
</div>
`,
context: args
});

const defaultArgs = {
items: FAKE_ITEMS,
selectedItems: FAKE_SELECTED_ITEMS,
Expand Down Expand Up @@ -142,6 +165,16 @@ export default {
},
control: { type: 'text' }
},
searchEnabled: {
description: 'Display the search field in the dropdown',
table: {
type: {
summary: 'boolean'
},
defaultValue: { summary: 'true' }
},
control: { type: 'boolean' }
},
onChange: {
description: 'Action executed when item is selected from selection section',
type: { required: true },
Expand Down Expand Up @@ -201,3 +234,13 @@ export const WithoutSelectedItem = {
selectedItems: []
}
};

export const WithoutSearch = {
args: {
searchEnabled: false
}
};

export const WithPrefix = {
render: PrefixTemplate
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface OSSPowerSelectArgs extends BaseDropdownArgs {
loadingMore?: boolean;
placeholder?: string;
searchPlaceholder?: string;
searchEnabled?: boolean;
addressableAs?: string;
onChange: (item: any, operation: OperationType) => void;
onSearch?: (keyword: string) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ module('Integration | Component | o-s-s/power-select', function (hooks) {
assert.dom('.upf-power-select').hasAttribute('open');
});

test('with a prefix named block', async function (assert) {
await render(hbs`
<OSS::PowerSelect @selectedItems={{this.selectedItems}} @items={{this.items}}
@onSearch={{this.onSearch}}>
<:prefix>
<span class="power-select-prefix">prefix</span>
</:prefix>
<:selected-item as |selectedItem|>
{{selectedItem}}
</:selected-item>
<:option-item as |item|>
{{item}}
</:option-item>
</OSS::PowerSelect>
`);

assert.dom('.power-select-prefix').hasText('prefix');
});

test('without a border when @borderless is true', async function (assert) {
await render(hbs`
<OSS::PowerSelect @selectedItems={{this.selectedItems}} @items={{this.items}}
Expand Down Expand Up @@ -285,6 +304,62 @@ module('Integration | Component | o-s-s/power-select', function (hooks) {
});
});

module('with @searchEnabled', () => {
Comment thread
Elodie-DeMatteis-Upf marked this conversation as resolved.
Resolved
test('does not render the search field when disabled', async function (assert) {
await render(hbs`
<OSS::PowerSelect @selectedItems={{this.selectedItems}} @items={{this.items}}
@searchEnabled={{false}}>
<:selected-item as |selectedItem|>
{{selectedItem}}
</:selected-item>
<:option-item as |item|>
{{item}}
</:option-item>
</OSS::PowerSelect>
`);

await click('.upf-power-select__array-container');

assert.dom('.upf-infinite-select input').doesNotExist();
});

test('renders the search field when enabled', async function (assert) {
await render(hbs`
<OSS::PowerSelect @selectedItems={{this.selectedItems}} @items={{this.items}}
@onSearch={{this.onSearch}} @searchEnabled={{true}}>
<:selected-item as |selectedItem|>
{{selectedItem}}
</:selected-item>
<:option-item as |item|>
{{item}}
</:option-item>
</OSS::PowerSelect>
`);

await click('.upf-power-select__array-container');

assert.dom('.upf-infinite-select input').exists();
});

test('renders the search field by default', async function (assert) {
await render(hbs`
<OSS::PowerSelect @selectedItems={{this.selectedItems}} @items={{this.items}}
@onSearch={{this.onSearch}}>
<:selected-item as |selectedItem|>
{{selectedItem}}
</:selected-item>
<:option-item as |item|>
{{item}}
</:option-item>
</OSS::PowerSelect>
`);

await click('.upf-power-select__array-container');

assert.dom('.upf-infinite-select input').exists();
});
});

module('with @onBottomReached', (hooks) => {
hooks.beforeEach(function () {
this.items = ['value1', 'value2', 'value3'];
Expand Down
Loading