[TikiWiki-commits] [Git][tikiwiki/tiki][29.x] [BP][FIX][UX] Element Plus Select: keep remote multiple selects usable after selection
"MAGENE Sem Joel \(@Jomagene\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <6a75532f251d3_3819f424895bf@gitlab-sidekiq-low-urgency-cpu-bound-v2-76995fd67b-62zjg.mail> |
MAGENE Sem Joel pushed to branch 29.x at Tiki Wiki CMS Groupware / Tiki
Commits:
7db62045 by MAGENE Sem Joel at 2026-08-07T03:30:49+00:00
[BP][FIX][UX] Element Plus Select: keep remote multiple selects usable after selection
---
* [BP][FIX][UX] Element Plus Select: keep remote multiple selects usable after selection
---
* [FIX][UX] Element Plus Select: keep remote multiple selects usable after selection
---
* [FIX][UX] Element Plus Select: keep remote multiple selects usable after selection
See merge request tikiwiki/tiki!10606
(cherry picked from commit 1d16f5d539269fbcb558d39366b81e4570c1eb06)
See merge request tikiwiki/tiki!10855
(cherry picked from commit c9e515b93cacd3b57f6982179210de1d34358565)
See merge request tikiwiki/tiki!10858
- - - - -
2 changed files:
- src/js/vue-widgets/element-plus-ui/src/components/Select/Select.vue
- src/js/vue-widgets/element-plus-ui/src/tests/components/Select.test.js
Changes:
=====================================
src/js/vue-widgets/element-plus-ui/src/components/Select/Select.vue
=====================================
@@ -56,6 +56,16 @@ const getOptionsProp = computed(() => {
});
const options = ref([]);
const wrapperRef = ref(null);
+const deduplicateOptionsByValue = (items) => {
+ const seenValues = new Set();
+ return items.filter((item) => {
+ if (seenValues.has(item.value)) {
+ return false;
+ }
+ seenValues.add(item.value);
+ return true;
+ });
+};
const handleValueChange = (value) => {
props.emitValueChange({
@@ -81,10 +91,10 @@ const remoteMethod = async (query) => {
const data = await response.json();
const loadedOptions = data.map(item => (typeof item === "string" ? { value: item, label: item }: item));
- const newOptions = [
+ const newOptions = deduplicateOptionsByValue([
...options.value.filter(item => modelValue.value.includes(item.value)),
...loadedOptions,
- ];
+ ]);
options.value = newOptions;
} catch (error) {
console.error('Error loading remote options:', error);
@@ -179,4 +189,4 @@ export const DATA_TEST_ID = {
</el-select>
</div>
</ConfigWrapper>
-</template>
\ No newline at end of file
+</template>
=====================================
src/js/vue-widgets/element-plus-ui/src/tests/components/Select.test.js
=====================================
@@ -242,6 +242,28 @@ describe("Select", () => {
expect(renderedOption2.getAttribute("label")).toBe(expectedData[0].label);
});
+ test("does not duplicate an already-selected option returned by remote search", async () => {
+ const givenProps = {
+ ...basicProps,
+ multiple: "true",
+ value: JSON.stringify(["foo"]),
+ remoteSourceUrl: "http://foo.bar",
+ };
+ const expectedData = [
+ { value: "foo", label: "Foo remote" },
+ { value: "baz", label: "Baz remote" },
+ ];
+
+ getFetchSpy(expectedData);
+
+ render(Select, { props: givenProps });
+
+ await ElSelect.mock.calls[0][0]["remote-method"]("query");
+
+ const renderedOptions = screen.getAllByTestId(DATA_TEST_ID.SELECT_OPTION);
+ expect(renderedOptions.map((option) => option.getAttribute("value"))).toEqual(["foo", "baz"]);
+ });
+
test("should not trigger the remote search when the query is empty", async () => {
const givenProps = {
...basicProps,
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/7db62045624aedbfd1668e1ccda08b3eade04223
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/7db62045624aedbfd1668e1ccda08b3eade04223
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs