DEV: Add default results option to user-chooser (#19521)
defaultSearchResults search option can be used to show a list of results by default, before any search ran, when the filter is empty.
This commit is contained in:
parent
d2e24f9569
commit
8f9933d1dd
|
@ -28,4 +28,18 @@ module("Integration | Component | select-kit/user-chooser", function (hooks) {
|
||||||
await this.subject.deselectItemByValue("bob");
|
await this.subject.deselectItemByValue("bob");
|
||||||
assert.strictEqual(this.subject.header().name(), "martin");
|
assert.strictEqual(this.subject.header().name(), "martin");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("can display default search results", async function (assert) {
|
||||||
|
this.set("options", {
|
||||||
|
customSearchOptions: {
|
||||||
|
defaultSearchResults: [{ username: "foo" }, { username: "bar" }],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await render(hbs`<UserChooser @options={{this.options}} />`);
|
||||||
|
|
||||||
|
await this.subject.expand();
|
||||||
|
assert.strictEqual(this.subject.rowByIndex(0).value(), "foo");
|
||||||
|
assert.strictEqual(this.subject.rowByIndex(1).value(), "bar");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -57,6 +57,9 @@ export default MultiSelectComponent.extend({
|
||||||
filter = filter || "";
|
filter = filter || "";
|
||||||
filter = filter.replace(/^@/, "");
|
filter = filter.replace(/^@/, "");
|
||||||
const options = this.selectKit.options;
|
const options = this.selectKit.options;
|
||||||
|
if (filter === "" && options?.customSearchOptions?.defaultSearchResults) {
|
||||||
|
return Promise.resolve(options.customSearchOptions.defaultSearchResults);
|
||||||
|
}
|
||||||
|
|
||||||
// prevents doing ajax request for nothing
|
// prevents doing ajax request for nothing
|
||||||
const skippedSearch = skipSearch(filter, options.allowEmails);
|
const skippedSearch = skipSearch(filter, options.allowEmails);
|
||||||
|
|
Loading…
Reference in New Issue