DEV: Add select-kit option to hide values from preview (#18002)

* DEV: Add select-kit option to hide values from preview
This commit is contained in:
Isaac Janzen 2022-08-19 11:39:58 -05:00 committed by GitHub
parent 36f766399d
commit ce30422d6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 1 deletions

View File

@ -125,5 +125,26 @@ module(
"it forces the max length of the tag"
);
});
test("values in hiddenFromPreview will not display in preview", async function (assert) {
this.set("value", ["foo", "bar"]);
this.set("hiddenValues", ["foo"]);
await render(
hbs`<MiniTagChooser @options={{hash allowAny=true hiddenValues=this.hiddenValues}} @value={{this.value}} />`
);
assert.strictEqual(
query(".formatted-selection").textContent.trim(),
"bar"
);
await this.subject.expand();
assert.deepEqual(
[...queryAll(".selected-content .selected-choice")].map((el) =>
el.textContent.trim()
),
["bar"]
);
});
}
);

View File

@ -59,7 +59,13 @@ export default MultiSelectComponent.extend(TagsMixin, {
}),
content: computed("value.[]", function () {
return makeArray(this.value).map((x) => this.defaultItem(x, x));
let values = makeArray(this.value);
if (this.selectKit.options.hiddenValues) {
values = values.filter(
(val) => !this.selectKit.options.hiddenValues.includes(val)
);
}
return values.map((x) => this.defaultItem(x, x));
}),
search(filter) {

View File

@ -293,6 +293,7 @@ export default Component.extend(
placementStrategy: null,
mobilePlacementStrategy: null,
desktopPlacementStrategy: null,
hiddenValues: null,
},
autoFilterable: computed("content.[]", "selectKit.filter", function () {