Skip to content

Commit 33de99d

Browse files
authored
Add option to pass @multiple in power-select-with-create (#170)
* Add option to pass `@multiple` in `power-select-with-create` * Update readme
1 parent 8e10db8 commit 33de99d

7 files changed

Lines changed: 144 additions & 55 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Please also refer to [Ember Power Select documentation](https://github.com/ciber
2929
</PowerSelectWithCreate>
3030
```
3131

32-
If you want to be able to select multiple options, use the `<PowerSelectMultipleWithCreate>` component instead. It has the same API as the normal `<PowerSelectWithCreate>`.
32+
If you want to be able to select multiple options, use the `<PowerSelectWithCreate>` component with parameter `@multiple={{true}}`.
3333

3434
For more options please refer to the [Ember Power Select docs](http://www.ember-power-select.com/docs).
3535

ember-power-select-with-create/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
"@rollup/plugin-babel": "^6.0.4",
5252
"babel-plugin-ember-template-compilation": "^2.2.5",
5353
"concurrently": "^9.1.2",
54-
"ember-basic-dropdown": "^8.6.1",
55-
"ember-power-select": "^8.7.1",
54+
"ember-basic-dropdown": "^8.8.0",
55+
"ember-power-select": "^8.12.0",
5656
"ember-source": "^6.4.0",
5757
"ember-template-lint": "^7.7.0",
5858
"eslint": "^9.26.0",
@@ -81,7 +81,7 @@
8181
},
8282
"peerDependencies": {
8383
"@glimmer/component": "^1.1.2 || ^2.0.0",
84-
"ember-basic-dropdown": "^8.6.1",
85-
"ember-power-select": "^8.7.1"
84+
"ember-basic-dropdown": "^8.8.0",
85+
"ember-power-select": "^8.12.0"
8686
}
8787
}

ember-power-select-with-create/src/components/power-select-with-create.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<this.powerSelectComponent
2+
@multiple={{@multiple}}
23
@afterOptionsComponent={{@afterOptionsComponent}}
34
@allowClear={{@allowClear}}
45
@ariaDescribedBy={{@ariaDescribedBy}}

ember-power-select-with-create/src/components/power-select-with-create.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ export default class PowerSelectWithCreateComponent extends Component {
8383

8484
@action
8585
selectOrCreate(selection, select, e) {
86+
if (this.args.multiple) {
87+
let suggestion = selection.filter((option) => {
88+
return option.__isSuggestion__;
89+
})[0];
90+
91+
if (suggestion) {
92+
this.args.onCreate(suggestion.__value__, select);
93+
} else {
94+
this.args.onChange(selection, select);
95+
}
96+
97+
return;
98+
}
99+
86100
if (selection && selection.__isSuggestion__) {
87101
this.args.onCreate(selection.__value__, select, e);
88102
} else {

pnpm-lock.yaml

Lines changed: 108 additions & 48 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test-app/app/templates/application.hbs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@
2626
<br>
2727
<br>
2828
<br>
29+
<h3>Multiple selections via <code>power-select-with-create</code> &amp; <code>@multiple={{true}}</code></h3>
30+
<PowerSelectWithCreate
31+
@multiple={{true}}
32+
@options={{this.countries}}
33+
@searchField="name"
34+
@selected={{this.selectedCountries}}
35+
@onChange={{fn (mut this.selectedCountries)}}
36+
@onCreate={{this.createCountry}} as |country|
37+
>
38+
{{country.name}}
39+
</PowerSelectWithCreate>
40+
<br>
41+
<br>
42+
<br>
2943
<h3>With custom Add message</h3>
3044
<PowerSelectWithCreate
3145
@options={{this.countries}}

0 commit comments

Comments
 (0)