diff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/mini-tag-chooser-test.js b/app/assets/javascripts/discourse/tests/integration/components/select-kit/mini-tag-chooser-test.js index c41aa7686a2..92a50d0e571 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/select-kit/mini-tag-chooser-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/mini-tag-chooser-test.js @@ -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`` + ); + 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"] + ); + }); } ); diff --git a/app/assets/javascripts/select-kit/addon/components/mini-tag-chooser.js b/app/assets/javascripts/select-kit/addon/components/mini-tag-chooser.js index 7a8aa6d0a67..b21a37e8c0a 100644 --- a/app/assets/javascripts/select-kit/addon/components/mini-tag-chooser.js +++ b/app/assets/javascripts/select-kit/addon/components/mini-tag-chooser.js @@ -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) { diff --git a/app/assets/javascripts/select-kit/addon/components/select-kit.js b/app/assets/javascripts/select-kit/addon/components/select-kit.js index 7cdc738b0de..bf30320f762 100644 --- a/app/assets/javascripts/select-kit/addon/components/select-kit.js +++ b/app/assets/javascripts/select-kit/addon/components/select-kit.js @@ -293,6 +293,7 @@ export default Component.extend( placementStrategy: null, mobilePlacementStrategy: null, desktopPlacementStrategy: null, + hiddenValues: null, }, autoFilterable: computed("content.[]", "selectKit.filter", function () {