Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[24.0] Replace Multiselect selectLabel with icons in FormSelect #18194

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/src/components/Form/Elements/FormSelect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const defaultOptions = [

function testDefaultOptions(wrapper) {
const target = wrapper.findComponent(MountTarget);
const options = target.findAll("li > span > span");
const options = target.findAll("li > span > div");
expect(options.length).toBe(4);
for (let i = 0; i < options.length; i++) {
expect(options.at(i).text()).toBe(`label_${i + 1}`);
Expand All @@ -52,7 +52,7 @@ describe("FormSelect", () => {
optional: true,
});
const target = wrapper.findComponent(MountTarget);
const options = target.findAll("li > span > span");
const options = target.findAll("li > span > div");
expect(options.length).toBe(5);
expect(options.at(0).text()).toBe("Nothing selected");
const selectedDefault = wrapper.find(".multiselect__option--selected");
Expand Down
26 changes: 16 additions & 10 deletions client/src/components/Form/Elements/FormSelect.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<script setup lang="ts">
import { library } from "@fortawesome/fontawesome-svg-core";
import { faCheckSquare, faSquare } from "@fortawesome/free-regular-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { computed, type ComputedRef, onMounted, type PropType, watch } from "vue";
import Multiselect from "vue-multiselect";

import { useMultiselect } from "@/composables/useMultiselect";
import { uid } from "@/utils/utils";

library.add(faCheckSquare, faSquare);

const { ariaExpanded, onOpen, onClose } = useMultiselect();

type SelectValue = Record<string, unknown> | string | number | null;
Expand Down Expand Up @@ -70,13 +75,6 @@ const reorderedOptions = computed(() => {
}
});

/**
* Configure deselect label
*/
const deselectLabel: ComputedRef<string> = computed(() => {
return props.multiple ? "Click to remove" : "";
});

/**
* Tracks if the select field has options
*/
Expand Down Expand Up @@ -163,16 +161,24 @@ onMounted(() => {
:aria-expanded="ariaExpanded"
:close-on-select="!multiple"
:disabled="disabled"
:deselect-label="deselectLabel"
:deselect-label="null"
label="label"
:multiple="multiple"
:options="reorderedOptions"
:placeholder="placeholder"
:selected-label="selectedLabel"
select-label="Click to select"
:select-label="null"
track-by="value"
@open="onOpen"
@close="onClose" />
@close="onClose">
<template v-slot:option="{ option }">
<div class="d-flex align-items-center justify-content-between">
<span>{{ option.label }}</span>
<FontAwesomeIcon v-if="selectedValues.includes(option.value)" :icon="faCheckSquare" />
<FontAwesomeIcon v-else :icon="faSquare" />
</div>
</template>
</Multiselect>
<slot v-else name="no-options">
<b-alert v-localize class="w-100" variant="warning" show> No options available. </b-alert>
</slot>
Expand Down
Loading