Skip to content

Commit

Permalink
Replace Multiselect selectLabel with icons in FormSelect
Browse files Browse the repository at this point in the history
Fixes #18150
  • Loading branch information
ahmedhamidawan committed May 21, 2024
1 parent 7ba9471 commit c4b51c6
Showing 1 changed file with 16 additions and 10 deletions.
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

0 comments on commit c4b51c6

Please sign in to comment.